-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Description
If a parser error is encountered the socket connection is restarted but the old one is not closed
https://github.com/socketio/socket.io-client/blob/4f6030f2c4394bc51d63fe27ed3310d95b9e0a74/lib/manager.ts#L425

Socket.IO server version: 4.1.2
Server
import { Server } from "socket.io";
const io = new Server(3000, {});
io.on("connection", (socket) => {
console.log(`connect ${socket.id}`);
socket.on("disconnect", () => {
console.log(`disconnect ${socket.id}`);
});
socket.on('notify', (msg: { channel: string; data: any }, callback) => {
const { channel, data } = msg;
socket.broadcast.emit(channel, data);
});
});Socket.IO client version: 4.7.2
Client
import { io } from "socket.io-client";
const socket = io("ws://localhost:3000/", {});
socket.on("connect", () => {
console.log(`connect ${socket.id}`);
});
socket.on("disconnect", () => {
console.log("disconnect");
});
//invalid emit, correct shape would be {channel: 'channel name': data: {records: []}}
socket.emit('notify', {records:[]})We had an invalid emit in our code that resulted in us broadcasting (null, null) from the server. This was fine until a semi recent update to the socket.io-parser (socketio/socket.io-parser@3b78117). It causes the client to throw a parser error and to create a second connection to the hub, and slowly over time, this leaks a lot of connections.
I would expect that if the reconnection code is called on the client there is an attempt to safely close the old connection or to check that it is dead before attempting a reconnection. or to skip this behaviour for a parser error
Platform:
- Device: M1 MacBook pro
- OS: 14.1.1 (23B81)