Skip to content

Commit 414a2e4

Browse files
committed
Fix persist worker exiting without processing newly arrived data
When persistWorker finds no pending history, a race window exists between reading pendingHistory as null and the cleanup modifyManagerState call. If queuePersist runs in that window, it sets pendingHistory but ensurePersistWorker sees the still-alive worker fiber and skips spawning a new one. The worker then exits, leaving a completed fiber reference that permanently blocks new workers from being created. Fix: return a flag from the cleanup indicating whether new data arrived in the interim, and continue the loop instead of returning when it did.
1 parent ab561b4 commit 414a2e4

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

apps/server/src/terminal/Layers/Manager.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,15 +837,21 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
837837
});
838838

839839
if (!startState) {
840-
yield* modifyManagerState((state) => {
840+
const hasPending = yield* modifyManagerState((state) => {
841841
const existing = state.persistStates.get(sessionKey);
842-
if (!existing || existing.pendingHistory !== null) {
843-
return [undefined, state] as const;
842+
if (!existing) {
843+
return [false, state] as const;
844+
}
845+
if (existing.pendingHistory !== null) {
846+
return [true, state] as const;
844847
}
845848
const persistStates = new Map(state.persistStates);
846849
persistStates.delete(sessionKey);
847-
return [undefined, { ...state, persistStates }] as const;
850+
return [false, { ...state, persistStates }] as const;
848851
});
852+
if (hasPending) {
853+
continue;
854+
}
849855
return;
850856
}
851857

0 commit comments

Comments
 (0)