socket.io-redis-adapter
socket.io-redis-adapter copied to clipboard
Receiving "Callbacks are not support when broadcasting" when using multiple webapps via socket.emit
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)
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
Implemented in [email protected]: https://github.com/socketio/socket.io/releases/tag/4.5.0 :rocket: