fix(worker): serialize box failure and idle reaping
This commit is contained in:
@@ -38,8 +38,14 @@ const scheduleReapIfIdle = (username: string) => {
|
||||
if (!box || box.refs.size > 0) return;
|
||||
if (box.idleTimer) clearTimeout(box.idleTimer);
|
||||
box.idleTimer = setTimeout(() => {
|
||||
void stopWorkspaceContainer(userContainerName(username));
|
||||
boxes.delete(username);
|
||||
void withLock(username, async () => {
|
||||
const current = boxes.get(username);
|
||||
if (current !== box || current.refs.size > 0) return;
|
||||
await stopWorkspaceContainer(current.name);
|
||||
if (boxes.get(username) === current && current.refs.size === 0) {
|
||||
boxes.delete(username);
|
||||
}
|
||||
});
|
||||
}, env.boxIdleMs);
|
||||
};
|
||||
|
||||
@@ -83,6 +89,10 @@ export const acquireUserBox = (args: {
|
||||
return handle;
|
||||
} catch (error) {
|
||||
handle.release();
|
||||
if (boxes.get(args.username) === box && box.refs.size === 0) {
|
||||
if (box.idleTimer) clearTimeout(box.idleTimer);
|
||||
boxes.delete(args.username);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user