kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.43k stars 123 forks source link

Suspicion of two concurrent room unsubscribes on client disconnect #2541

Open psam44 opened 2 months ago

psam44 commented 2 months ago

Consider this client scenario (even if not regular):

const ws = new WebSocket("...", { port: ... });
const kuzzle = new Kuzzle(ws, ...);
await kuzzle.connect();
await kuzzle.auth.login("local", ...credentials...);
await kuzzle.realtime.subscribe("...index...", "...collection...", {}, ...callback...);
kuzzle.disconnect()

An error appears in log:

{"level":"error","message":"2024-07-04 09-46-45 [LOG:ERROR] [knode-sarcastic-shannon-82790]
 PreconditionError: User \"ec...14\" has not subscribed to \"2d...ef\"."}

Reading the sources, I guess this may be an explanation:

This leads to two calls to unsubscribe(). One is run correctly, and empties connectionRooms at some time. The other one would progress enough meanwhile, but fail at the check for a non empty connectionRooms, so:

throw realtimeError.get("not_subscribed", connectionId, roomId);
rolljee commented 1 month ago

Hello and thank you for your analysis on this issue, we will have a look into it