Description
In ClusterAdapter.broadcast() (cluster-adapter.js, line 242–261), when
publishAndReturnOffset() rejects (e.g. due to a serialization error in the
adapter layer), the catch block does a return debug(...) which
prevents super.broadcast(packet, opts) from ever being called.
This means sockets connected to the same server instance that emitted the
event also never receive it — a completely silent failure.
Affected code
// cluster-adapter.js lines 242–261
async broadcast(packet, opts) {
const onlyLocal = opts?.flags?.local;
if (!onlyLocal) {
try {
const offset = await this.publishAndReturnOffset({
type: MessageType.BROADCAST,
data: { packet, opts: encodeOptions(opts) },
});
this.addOffsetIfNecessary(packet, opts, offset);
} catch (e) {
return debug("[%s] error while broadcasting message: %s", this.uid, e.message);
// ^^^ `return` here means super.broadcast() below is NEVER reached
}
}
super.broadcast(packet, opts); // ← never called when catch fires
}
Steps to reproduce
- Use createShardedAdapter (Redis 7+ sharded pub/sub) with an ioredis Cluster.
- Emit an event where the payload causes encode() inside doPublish() to throw
(e.g. a Mongoose document — see related issue in @socket.io/redis-adapter).
- Observe that no connected socket receives the event, including sockets on
the same Node.js process.
Expected behaviour
When remote publishing fails, the error should be logged but super.broadcast() should still be called so that local sockets on the same server instance receive the event.
Environment
- socket.io-adapter: 2.x (ClusterAdapter / ClusterAdapterWithHeartbeat)
- @socket.io/redis-adapter: 8.3.x (ShardedRedisAdapter)
- Redis: 7.x cluster with sharded pub/sub (SPUBLISH/SSUBSCRIBE)
- Node.js: 18.x
Description
In
ClusterAdapter.broadcast()(cluster-adapter.js, line 242–261), whenpublishAndReturnOffset()rejects (e.g. due to a serialization error in theadapter layer), the
catchblock does areturn debug(...)whichprevents
super.broadcast(packet, opts)from ever being called.This means sockets connected to the same server instance that emitted the
event also never receive it — a completely silent failure.
Affected code
Steps to reproduce
(e.g. a Mongoose document — see related issue in @socket.io/redis-adapter).
the same Node.js process.
Expected behaviour
When remote publishing fails, the error should be logged but super.broadcast() should still be called so that local sockets on the same server instance receive the event.
Environment