Skip to content

Commit

Permalink
fix: prevent socket from reconnecting after middleware failure
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Nov 16, 2021
1 parent ccf7998 commit d54d12c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export class Socket<
break;

case PacketType.CONNECT_ERROR:
this.destroy();
const err = new Error(packet.data.message);
// @ts-ignore
err.data = packet.data.data;
Expand Down
17 changes: 17 additions & 0 deletions test/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ describe("socket", function () {
});
});

it("should not try to reconnect after a middleware failure", (done) => {
const socket = io("/no", { forceNew: true, reconnectionDelay: 10 });

let count = 0;

socket.on("connect_error", () => {
count++;
// force reconnection
socket.io.engine.close();
});

setTimeout(() => {
expect(count).to.eql(1);
done();
}, 100);
});

it("should throw on reserved event", () => {
const socket = io("/no", { forceNew: true });

Expand Down

0 comments on commit d54d12c

Please sign in to comment.