Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emits to clients connected to different node processes do not work after handling node-mubsub channel error #21

Open
gsRatti1 opened this issue Aug 24, 2021 · 0 comments

Comments

@gsRatti1
Copy link

gsRatti1 commented Aug 24, 2021

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

Here is how the method looks like

function Channel(connection, name, options) {
options || (options = {});
options.capped = true;
options.size || (options.size = 1024 * 1024 * 5);

this.options = options;
this.connection = connection;
this.closed = false;
this.listening = null;
this.name = name || 'mubsub';

const channel = this.create();
> channel.on('error', function (err) {
console.error(err);
});
,
channel.listen();
this.setMaxListeners(0);
}

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant