fix: calling destroy() should clear all internal state

If a client was in the process of receiving some binary attachments
when the connection was abruptly closed, then the manager would call
`decoder.destroy()` ([1]) but was then stuck in a "parse error" loop
upon reconnection (since it expected a binary attachment and not a
CONNECT packet).

[1]: a1c528b089/lib/manager.ts (L520)
This commit is contained in:
Damien Arrachequesne
2023-01-19 09:13:04 +01:00
parent ae8dd88995
commit 22c42e3545
3 changed files with 16 additions and 21 deletions

View File

@@ -69,27 +69,6 @@ describe("ArrayBuffer", () => {
return helpers.test_bin(packet);
});
it("cleans itself up on close", () => {
const packet = {
type: PacketType.EVENT,
data: ["a", new ArrayBuffer(2), new ArrayBuffer(3)],
id: 0,
nsp: "/",
};
const encodedPackets = encoder.encode(packet);
const decoder = new Decoder();
decoder.on("decoded", (packet) => {
throw new Error("received a packet when not all binary data was sent.");
});
decoder.add(encodedPackets[0]); // add metadata
decoder.add(encodedPackets[1]); // add first attachment
decoder.destroy(); // destroy before all data added
expect(decoder.reconstructor.buffers.length).to.be(0); // expect that buffer is clean
});
it("should not modify the input packet", () => {
const packet = {
type: PacketType.EVENT,