Closed myndzi closed 1 year ago
Note: if the client is subscribed to a different pubsub topic, it receives the result it was intended to. This produces the expected result:
const uWS = require('uWebSockets.js');
const { WebSocket } = require('ws');
const app = uWS
.App()
.ws('/', {
open: (ws) => {
ws.subscribe('other'); // new
ws.subscribe('test');
app.publish('test', 'hi from pubsub');
ws.unsubscribe('test');
ws.send('???');
}
})
.listen(3300, () => {
const wsClient = new WebSocket('ws://localhost:3300/');
wsClient.addEventListener('message', (evt) => {
const msg = Buffer.from(evt.data).toString();
console.log('client received from server:', msg);
if (msg === '???') app.close();
});
});
Edit: come to think of it, this was probably the difference-maker in my attempted reproduction, since I had a bug in my actual code where I forgot to subscribe users to the lobby, so I wasn't getting the control message since the users, once unsubscribed, were present in 0 pubsub topics. But since I had intended them to be in the lobby, my repro code didn't have that bug and worked unexpectedly...
https://github.com/uNetworking/uWebSockets/commit/7da88ce71c31dbc799dfa9bdd8171d09a6b80b19
Will release this if it passes fuzzing
Thank you! One Q: looking at the diff, is there anything that cleans these up? This feels leaky to me, though it will solve the problem. Is there no place to remove the subscriber once all messages have been flushed?
freeSubscriber is not per topic, it's more like "downgrade this WebSocket to not using pub/sub". It happens in close either way.
In a few hours, can you test bun install uNetworking/uWebSockets.js#binaries with these changes
Did that work?
Did that work?
Yep, thank you!
Yeah I ran your reproducer and saw it was fixed. Thanks for reporting, there is a new release both .js and c++
According to the release notes:
I have a case where I'm working on the backend for an existing application; I'm using pub/sub to represent game lobbies. When the host leaves the room, a control message is sent to the topic, and then each subscribed client is unsubscribed. However, the control message is not being sent.
I managed to thin it down to a minimum reproducible version, though my initial attempts seemed to work as expected. I was unable to determine the significant difference between my initial attempts and the repro case below. I've been at it some hours, hopefully this is actually a repro case and not user error.