Skip to content

Commit 2403b88

Browse files
fix: do not swallow user exceptions
Following [1], any exception in a user-provided event listener would get caught in the try...catch of the decoder and result in the reconnection of the socket. [1]: c597023 Related: - #1551 - #1554 - #1557
1 parent 1098618 commit 2403b88

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

lib/manager.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Socket as Engine,
33
SocketOptions as EngineOptions,
44
installTimerFunctions,
5+
nextTick,
56
} from "engine.io-client";
67
import { Socket, SocketOptions, DisconnectDescription } from "./socket.js";
78
import * as parser from "socket.io-parser";
@@ -427,7 +428,7 @@ export class Manager<
427428
try {
428429
this.decoder.add(data);
429430
} catch (e) {
430-
this.onclose("parse error");
431+
this.onclose("parse error", e as Error);
431432
}
432433
}
433434

@@ -437,7 +438,10 @@ export class Manager<
437438
* @private
438439
*/
439440
private ondecoded(packet): void {
440-
this.emitReserved("packet", packet);
441+
// the nextTick call prevents an exception in a user-provided event listener from triggering a disconnection due to a "parse error"
442+
nextTick(() => {
443+
this.emitReserved("packet", packet);
444+
}, this.setTimeoutFn);
441445
}
442446

443447
/**

lib/socket.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -725,5 +725,6 @@ export namespace Socket {
725725
| "io client disconnect"
726726
| "ping timeout"
727727
| "transport close"
728-
| "transport error";
728+
| "transport error"
729+
| "parse error";
729730
}

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"dependencies": {
3535
"@socket.io/component-emitter": "~3.1.0",
3636
"debug": "~4.3.2",
37-
"engine.io-client": "~6.2.1",
37+
"engine.io-client": "~6.2.3",
3838
"socket.io-parser": "~4.2.0"
3939
},
4040
"devDependencies": {

0 commit comments

Comments
 (0)