mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
fix: only lock shared tasks if an exclusive is running
This commit is contained in:
@@ -49,8 +49,7 @@ class RepositoryMutex {
|
|||||||
async acquireShared(repositoryId: string, operation: string): Promise<() => void> {
|
async acquireShared(repositoryId: string, operation: string): Promise<() => void> {
|
||||||
const state = this.getOrCreateState(repositoryId);
|
const state = this.getOrCreateState(repositoryId);
|
||||||
|
|
||||||
const hasExclusiveWaiter = state.waitQueue.some((w) => w.type === "exclusive");
|
if (!state.exclusiveHolder) {
|
||||||
if (!state.exclusiveHolder && !hasExclusiveWaiter) {
|
|
||||||
const lockId = this.generateLockId();
|
const lockId = this.generateLockId();
|
||||||
state.sharedHolders.set(lockId, {
|
state.sharedHolders.set(lockId, {
|
||||||
id: lockId,
|
id: lockId,
|
||||||
@@ -60,7 +59,9 @@ class RepositoryMutex {
|
|||||||
return () => this.releaseShared(repositoryId, lockId);
|
return () => this.releaseShared(repositoryId, lockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`[Mutex] Waiting for shared lock on repo ${repositoryId}: ${operation}`);
|
logger.debug(
|
||||||
|
`[Mutex] Waiting for shared lock on repo ${repositoryId}: ${operation} (exclusive held by: ${state.exclusiveHolder.operation})`,
|
||||||
|
);
|
||||||
const lockId = await new Promise<string>((resolve) => {
|
const lockId = await new Promise<string>((resolve) => {
|
||||||
state.waitQueue.push({ type: "shared", operation, resolve });
|
state.waitQueue.push({ type: "shared", operation, resolve });
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user