Fix race condition of client-side path deconflicting

This commit is contained in:
Andras Schmelczer 2025-11-29 17:28:03 +00:00
parent 952e89343a
commit 10bde4bc3a
4 changed files with 77 additions and 28 deletions

View file

@ -78,7 +78,7 @@ export class Locks<T> {
* @param key The key to lock
* @returns `true` if lock acquired, `false` if already locked
*/
private tryLock(key: T): boolean {
public tryLock(key: T): boolean {
if (this.locked.has(key)) {
return false;
}
@ -95,7 +95,7 @@ export class Locks<T> {
* @param key The key to wait for and lock
* @returns Promise that resolves when lock is acquired
*/
private async waitForLock(key: T): Promise<void> {
public async waitForLock(key: T): Promise<void> {
if (this.tryLock(key)) {
return Promise.resolve();
}
@ -121,9 +121,9 @@ export class Locks<T> {
* @param key The key to unlock
* @throws {Error} If key is not currently locked
*/
private unlock(key: T): void {
public unlock(key: T): void {
if (!this.locked.has(key)) {
throw new Error(`Key '${key}' is not locked, cannot unlock`);
return;
}
// Remove first waiter to ensure FIFO order