From c218468f67259e7d9b14f611c2a4c441f900ae82 Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Mon, 6 Aug 2012 13:03:51 -0700 Subject: [PATCH] Fix infinite recursion in Websocket parsers. If a client is feeding messages faster than server can handle them, infinite recursion occurs. Basically, the "overflow" data gets added to the parser and it immediately parses a new message. The fix pushes the processing of the next message (in this edge case) onto the event queue. This prevents the stack from recursing indefinitely. This also prevents a fast client from starving other clients. --- lib/transports/websocket/hybi-07-12.js | 2 +- lib/transports/websocket/hybi-16.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/transports/websocket/hybi-07-12.js b/lib/transports/websocket/hybi-07-12.js index 44f666a543..09ea1d5a26 100644 --- a/lib/transports/websocket/hybi-07-12.js +++ b/lib/transports/websocket/hybi-07-12.js @@ -464,7 +464,7 @@ Parser.prototype.add = function(data) { var bufferForHandler = this.expectBuffer; this.expectBuffer = null; this.expectOffset = 0; - this.expectHandler.call(this, bufferForHandler); + process.nextTick(this.expectHandler.bind(this, bufferForHandler)); } } diff --git a/lib/transports/websocket/hybi-16.js b/lib/transports/websocket/hybi-16.js index 69967dad28..5102f3837b 100644 --- a/lib/transports/websocket/hybi-16.js +++ b/lib/transports/websocket/hybi-16.js @@ -463,7 +463,7 @@ Parser.prototype.add = function(data) { var bufferForHandler = this.expectBuffer; this.expectBuffer = null; this.expectOffset = 0; - this.expectHandler.call(this, bufferForHandler); + process.nextTick(this.expectHandler.bind(this, bufferForHandler)); } }