I am using @nodebb/socket.io-adapter-mongo package for being able to broadcast messages to clients connected to different node processes (from a particular node process).
This is how we attach the adapter:
import * as SocketMongoAdaptor from '@nodebb/socket.io-adapter-mongo';
socketServer.adapter(SocketMongoAdaptor('mongodb-conn-string'));
This is how we emit broadcast message
socket.to(room-name).emit('event', payload);
The clients present in 'room-name' can be connected to different node processes. From one node process, I want to send a message to all those clients.
This seems to work fine. However, we have seen some flaky behavior where the clients do not receive the messages sent by the server. Debugging further we found the following :
So, the adapter library uses @nodebb/mubsub library internally. We have added a patch for this library to handle the channel error. We did this because, without the error handler in place, mongo events like topology description changed, mongo network error used to result in crashing of the node process (the mubusb channel used to emit a connection error, which went unhandled and terminated the node process).
So we added a patch to handle the channel error in 'Channel' function in this file https://github.com/NodeBB/mubsub/blob/master/lib/channel.js
Now , what happens is that , once this error handler is executed, message broadcast to different processes stops working. Note that broadcast within the same process still works fine.
So, if two clients are connected to different node processes, then after the mubsub channel error occurs, socket io emit from one process to the other does not work.
But if the clients connect to the same node process , things work fine.
Is it that since we are handling the error, the mubsub cursor always remains broken, and inter process communication does not work, unless the node processes are restarted so that a new channel/connection is established.
My expectation is that mubsub should automatically reconnect/re-establish the channel (I think autoReconnect is true by default)
I am using @nodebb/socket.io-adapter-mongo package for being able to broadcast messages to clients connected to different node processes (from a particular node process).
This is how we attach the adapter:
This is how we emit broadcast message
socket.to(room-name).emit('event', payload);
The clients present in 'room-name' can be connected to different node processes. From one node process, I want to send a message to all those clients.
This seems to work fine. However, we have seen some flaky behavior where the clients do not receive the messages sent by the server. Debugging further we found the following :
So, the adapter library uses @nodebb/mubsub library internally. We have added a patch for this library to handle the channel error. We did this because, without the error handler in place, mongo events like topology description changed, mongo network error used to result in crashing of the node process (the mubusb channel used to emit a connection error, which went unhandled and terminated the node process). So we added a patch to handle the channel error in 'Channel' function in this file https://github.com/NodeBB/mubsub/blob/master/lib/channel.js
Here is how the method looks like
Now , what happens is that , once this error handler is executed, message broadcast to different processes stops working. Note that broadcast within the same process still works fine. So, if two clients are connected to different node processes, then after the mubsub channel error occurs, socket io emit from one process to the other does not work. But if the clients connect to the same node process , things work fine.
Is it that since we are handling the error, the mubsub cursor always remains broken, and inter process communication does not work, unless the node processes are restarted so that a new channel/connection is established. My expectation is that mubsub should automatically reconnect/re-establish the channel (I think autoReconnect is true by default)