socket.io-redis-adapter icon indicating copy to clipboard operation
socket.io-redis-adapter copied to clipboard

Receiving "Callbacks are not support when broadcasting" when using multiple webapps via socket.emit

Open Lucaszw opened this issue 3 years ago • 1 comments

We are using socket io callbacks when sending messages to particular connections. (We use heroku for hosting)

Server emit code looks like

const sockets  = await this.deviceSockets.in(channelName).fetchSockets()
for (const socket of sockets) {
socket.emit(eventName, ...args, function(err, result) {
...
});
}

Client code looks like

socket.on('ping', async (callback) => {
callback({ status: 'ok' })
})

This works fine when we only have one web server running; however when we have multiple webservers running (heroku dynos), we receive the following error when our clients try responding to the callbacks:

Callbacks are not support when broadcasting

However we aren't broadcasting (rather emitting to one particular client)

We are configuring socket-io redis in the following way:

const {createAdapter} = require('@socket.io/redis-adapter')
...
const pubClient = redis.createClient({...})
const subClient = this.pubClient.duplicate()
io.adapter(createAdapter(pubClient,subClient)

Lucaszw avatar Mar 12 '22 11:03 Lucaszw

Hi! That's indeed a known limitation, acknowledgements across multiple servers are not currently supported. We plan to implement it in the next release though.

Related: https://github.com/socketio/socket.io/issues/1811

darrachequesne avatar Mar 15 '22 06:03 darrachequesne

Implemented in [email protected]: https://github.com/socketio/socket.io/releases/tag/4.5.0 :rocket:

darrachequesne avatar Dec 07 '22 09:12 darrachequesne