WebSocket-Node
WebSocket-Node copied to clipboard
Remove race condition when server closes connection
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!
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.
Is this still an issue? At least the tests should get merged no?