Skip to content

Commit d2ecaff

Browse files
author
mlinnell
committed
Fixed memory leak in WebSocket transport.
The WebSocket.buffer would continue to grow, unabated, for each new message. This buffer is now only utilized to process the nonce, and is set to empty (and no longer filled) once nonce has been received. Parser instance appears to handle all message buffering, instead of WebSocket entity.
1 parent 023566e commit d2ecaff

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

lib/socket.io/transports/websocket.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,15 @@ WebSocket.prototype._onConnect = function(req, socket){
9999
this.buffer = "";
100100

101101
this.connection.addListener('data', function(data){
102-
self.buffer += data;
103102
if (self.waitingForNonce) {
103+
self.buffer += data;
104+
104105
if (self.buffer.length < 8) { return; }
105106
// Restore the connection to utf8 encoding after receiving the nonce
106107
self.connection.setEncoding('utf8');
107108
self.waitingForNonce = false;
108109
// Stuff the nonce into the location where it's expected to be
109110
self.upgradeHead = self.buffer.substr(0,8);
110-
self.buffer = self.buffer.substr(8);
111-
if (self.buffer.length > 0) {
112-
self.parser.add(self.buffer);
113-
}
114111
if (self._proveReception(self._headers)) { self._payload(); }
115112
return;
116113
}

0 commit comments

Comments
 (0)