-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Using xhr-streaming, xhr-polling, or jsonp-polling, if an error is raised in the socket.onmessage event handler, then the next time a message is received SockJS will replay the message that caused the error.
For example, message A is received and the client onmessage
event handler throws an uncaught error; later, message B is received, and onmessage
is called again with message A.
Repro repo: https://github.com/jcheng5/sockjs-error-test
The problem appears to be here:
sockjs-client/lib/transport/receiver/xhr.js
Lines 40 to 52 in 71876b3
for (var idx = -1; ; this.bufferPosition += idx + 1) { | |
var buf = text.slice(this.bufferPosition); | |
idx = buf.indexOf('\n'); | |
if (idx === -1) { | |
break; | |
} | |
var msg = buf.slice(0, idx); | |
if (msg) { | |
debug('message', msg); | |
this.emit('message', msg); | |
} | |
} | |
}; |
When this.emit('message', msg);
throws an exception, this.bufferPosition
doesn't get updated (third clause of the for-loop). If you update this.bufferPosition
before emitting the message, the problem goes away.