Skip to content

Commit fe07aee

Browse files
committed
fix from comment
1 parent 8ecc767 commit fe07aee

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

agents/src/ipc/proc_pool.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,17 @@ describe('ProcPool warmed process lock handling', () => {
5353
expect(unlock).toHaveBeenCalledTimes(1);
5454
expect(executor.close).toHaveBeenCalledTimes(1);
5555
});
56+
57+
it('releases both init and proc locks when closed before proc starts', async () => {
58+
const pool = new ProcPool('agent', 1, 1000, 1000, undefined, 0, 0);
59+
const initUnlock = vi.fn();
60+
const procUnlock = vi.fn();
61+
pool.closed = true;
62+
pool.initMutex.lock = vi.fn(async () => initUnlock);
63+
64+
await pool.procWatchTask(procUnlock);
65+
66+
expect(initUnlock).toHaveBeenCalledTimes(1);
67+
expect(procUnlock).toHaveBeenCalledTimes(1);
68+
});
5669
});

agents/src/ipc/proc_pool.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,28 @@ export class ProcPool {
9696
this.executors.push(proc);
9797

9898
const unlock = await this.initMutex.lock();
99-
if (this.closed) {
100-
return;
101-
}
102-
103-
await proc.start();
99+
let procUnlockTransferred = false;
104100
try {
105-
await proc.initialize();
106-
await this.warmedProcQueue.put({ proc, unlock: procUnlock });
107-
} catch {
108-
// Initialization failed before enqueue, so release the acquired slot immediately.
109-
procUnlock();
110-
}
101+
if (this.closed) {
102+
return;
103+
}
104+
105+
await proc.start();
106+
try {
107+
await proc.initialize();
108+
await this.warmedProcQueue.put({ proc, unlock: procUnlock });
109+
procUnlockTransferred = true;
110+
} catch {
111+
// Initialization failed before enqueue, so release the acquired slot immediately.
112+
}
111113

112-
unlock();
113-
await proc.join();
114+
await proc.join();
115+
} finally {
116+
unlock();
117+
if (!procUnlockTransferred) {
118+
procUnlock();
119+
}
120+
}
114121
} finally {
115122
const procIndex = this.executors.indexOf(proc);
116123
if (procIndex !== -1) {

0 commit comments

Comments
 (0)