Closed
Description
I am getting an error in my application after moving up to version 4.7.5
. When I run with previous versions, including 4.7.4
, everything works properly. The error I receive is:
node_modules/socket.io/dist/parent-namespace.js:88
this.children.forEach((nsp) => {
^
TypeError: Cannot read properties of undefined (reading 'forEach')
at ParentBroadcastAdapter.broadcast (node_modules/socket.io/dist/parent-namespace.js:88:23)
at BroadcastOperator.emit (node_modules/socket.io/dist/broadcast-operator.js:169:26)
at Socket.<anonymous> (server.js:60:33)
at Socket.emit (node:events:520:28)
at Socket.emitReserved (node_modules/socket.io/dist/typed-events.js:56:22)
at Socket._onclose (node_modules/socket.io/dist/socket.js:547:14)
at Client.onclose (node_modules/socket.io/dist/client.js:247:20)
at Socket.emit (node:events:532:35)
at Socket.onClose (node_modules/engine.io/build/socket.js:304:18)
at Object.onceWrapper (node:events:639:28)
When the following code was added in PR 4950 it appears that the code forgot to store or copy the children
parameter.
socket.io/lib/parent-namespace.ts
Line 121 in b0568b2
I think the code should be modified something like:
class ParentBroadcastAdapter extends Adapter {
private readonly children: Set<
Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>
> ;
constructor(parentNsp: any, private readonly children: Set<Namespace>) {
super(parentNsp);
this.children = children;
}
broadcast(packet: any, opts: BroadcastOptions) {
this.children.forEach((nsp) => {
nsp.adapter.broadcast(packet, opts);
});
}
}