-
-
Notifications
You must be signed in to change notification settings - Fork 524
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
Enforce room ID uniqueness #467
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
bump |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
bump |
@endel never tried it with a number but did not work as a string. But I solved my issue by defining/ using another custom property and it seems to work |
@endel I also only tried with strings. |
I'm doing this via a Redis lock personally, enforcing the acquisition of a lock in async onCreate(options) {
const myCustomId = options.my_custom_id?.toString();
if (!myCustomId) {
throw new Error('No ID provided');
}
const obtainedLock = await this.presence.pub.set(`room-${myCustomId}`, 1, 'NX');
if (obtainedLock !== 'OK') {
throw new Error('Room already exists');
}
this.roomId = myCustomId;
...
}
async onDispose() {
await this.presence.pub.del(`room-${this.roomId}`);
} |
Steps to Reproduce (for bugs)
onCreate
ofBattleRoom
, assign a customroomId
joinOrCreate
simultaneously from many clients, with the samepassword
joinBy
. It seems clients still get split into multiple rooms even if I sort the rooms by ascending creation date.Context
I was trying to create rooms with a fixed ID matching an ID provided by another service, but this seems to break
joinOrCreate
.This seems to be due to a race condition in the finding of a suitable room, which checks there is no room available, then creates one. If two requests are processed simultaneously, two rooms will be created.
I tried making the
roomId
index in MongoDB unique, but as the colyseus server did not handle the database errors appropriately, I did not investigate this further.It seems to me we either need:
Your Environment
The text was updated successfully, but these errors were encountered: