-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Race condition with dynamic namespaces #4136
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
sebamarynissen
added a commit
to sebamarynissen/socket.io
that referenced
this issue
Oct 22, 2021
5 tasks
PR filed (#4137). |
darrachequesne
pushed a commit
that referenced
this issue
Oct 24, 2021
Using an async operation with `io.use()` could lead to the creation of several instances of a same namespace, each of them overriding the previous one. Example: ```js io.use(async (nsp, auth, next) => { await anOperationThatTakesSomeTime(); next(); }); ``` Related: #4136
Good catch! Thanks for the detailed analysis 👍 This should be fixed by 9d86397 |
dzad
pushed a commit
to dzad/socket.io
that referenced
this issue
May 29, 2023
Using an async operation with `io.use()` could lead to the creation of several instances of a same namespace, each of them overriding the previous one. Example: ```js io.use(async (nsp, auth, next) => { await anOperationThatTakesSomeTime(); next(); }); ``` Related: socketio#4136
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
I have noticed that a race condition exists with dynamic namespaces. Consider the following setup
If the query to the database takes some time and a lot of clients are trying to connect to the same namespace in a short period of time, the namespace will be created multiple times. This will result in sockets being connected to a namespace that is overridden by another one, and hence they will no longer be receiving events.
Looking at
Server.prototype._checkNamespace
, I think this can be solved as follows:I will file a PR to solve this.
Context
The odds of this race condition happening are obviously rather low, but I experienced them on a website of mine where I organize tournaments. If the tournament starts, people are all sent to a socket.io namespace where their match is hosted. These namespaces are created dynamically, and so it happens that a large amount of people tries to connect at the same moment.
The text was updated successfully, but these errors were encountered: