socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Bug in socket.io-adapter: broadcast() calls encoder.encode with no callback

Open hemme opened this issue 5 years ago • 2 comments

Bug in socket.io-adapter: Adapter.broadcast() calls Encoder.encode with no callback

Adapter.broadcast() is calling this.encoder.encode without passing a callback function. This causes a runtime exception, like this:

UnhandledPromiseRejectionWarning: TypeError: callback is not a function
    at Encoder.encode (.........\node_modules\socket.io-parser\index.js:135:5)
    at ClusterAdapter.broadcast (.........\node_modules\@socket.io\cluster-adapter\node_modules\socket.io-adapter\dist\index.js:107:45)
    at ClusterAdapter.onMessage (.........\node_modules\@socket.io\cluster-adapter\dist\index.js:90:23)
    at process.emit (events.js:323:22)

Source code from node_modules\@socket.io\cluster-adapter\node_modules\socket.io-adapter\dist\index.js

        const flags = opts.flags || {};
        const basePacketOpts = {
            preEncoded: true,
            volatile: flags.volatile,
            compress: flags.compress
        };
        packet.nsp = this.nsp.name;
        const encodedPackets = this.encoder.encode(packet);

hemme avatar Oct 24 '21 10:10 hemme

Hi! Looks like a version incompatibilty. Which version of @socket.io/cluster-adapter and socket.io are you using?

darrachequesne avatar Oct 25 '21 20:10 darrachequesne

In effect I was using socket.io 2.x. Switching to 4.1 solved the problem.

hemme avatar Oct 25 '21 21:10 hemme