Automattic/engine.io — pull request #294 by lpinca (2014-10-25 21:00:35+00:00)
Title: socket: flush the write buffer before closing the socket (fixes #293)

This ensures that all the packets in the `writeBuffer` are sent to the transport before trying to close it.

**Note:** it is totally possible that the `close` method is called when the transport is still executing its `send` method, see [here](https://github.com/Automattic/engine.io/blob/0cc7cdfe6cbe4167e1df7081b8f9312344e7723f/lib/transports/websocket.js#L87-L97). In this case the socket is closed anyway and remaining messages will not have their callback executed due to [this](https://github.com/Automattic/engine.io/blob/0cc7cdfe6cbe4167e1df7081b8f9312344e7723f/lib/socket.js#L245) cleanup.
I don't know if it is better to refactor the WebSocket `send` method and defer the `close` invocation.