WebSocket-Node icon indicating copy to clipboard operation
WebSocket-Node copied to clipboard

Remove race condition when server closes connection

Open mathbruyen opened this issue 9 years ago • 2 comments

When server closes connection right after having sent some frames, those are ignored by the client. Frames are lost because they are processed in a nextTick/setImmediate callback, thus socket close event may arrive before they are actually processed.

Added a test that reproduces the error, on my computer it states that it received only 6 frames. I wonder if that could be computer-dependent so if that does not reproduce, try increasing to var count = 100; to something much larger.

The fix proposed here does not look right as it disables something done on purpose, as per the comment above (that's why I just commented out the line and not fixed the now useless bound method, I don't think this will be the real solution). Trying to delay socket end handling leads to socket errors, and I did not find anything better, so at least putting something that makes tests green. Welcome to any idea!

mathbruyen avatar Sep 09 '16 20:09 mathbruyen

Yes, this is a potentially challenging/sticky situation. I went back and forth on this a few times in the initial design/implementation of the library. It'll take some careful changes to implement this correctly.

theturtle32 avatar Mar 09 '17 17:03 theturtle32

Is this still an issue? At least the tests should get merged no?

formula1 avatar Feb 25 '22 03:02 formula1