diff --git a/lib/socket.io/transports/xhr-polling.js b/lib/socket.io/transports/xhr-polling.js index 112534c741..e98f73c2ae 100644 --- a/lib/socket.io/transports/xhr-polling.js +++ b/lib/socket.io/transports/xhr-polling.js @@ -72,8 +72,16 @@ Polling.prototype._write = function(message){ if (this.request.headers.cookie) headers['Access-Control-Allow-Credentials'] = 'true'; } this.response.writeHead(200, headers); - this.response.write(message); - this.response.end(); - this._onClose(); + var flushed = this.response.write(message); + if (flushed) { + this.response.end(); + this._onClose(); + } else { + var self = this; + this.response.connection.on("drain", function() { + self.response.end(); + self._onClose(); + }); + } } };