fix: serialize session lifecycle transitions
This commit is contained in:
@@ -174,9 +174,16 @@ export class PiProcessManager {
|
||||
|
||||
teardown(id: string): void {
|
||||
const rt = this.runtimes.get(id);
|
||||
if (rt) {
|
||||
rt.child.kill();
|
||||
this.runtimes.delete(id);
|
||||
}
|
||||
if (rt) this.teardownIfCurrent(id, rt);
|
||||
}
|
||||
|
||||
/** Remove only the runtime identity the caller observed. */
|
||||
teardownIfCurrent(id: string, expected: SessionRuntime): boolean {
|
||||
if (this.runtimes.get(id) !== expected) return false;
|
||||
// Delete before signalling the child so its asynchronous exit cannot be mistaken for a
|
||||
// crash, and so a replacement installed by a later lifecycle operation is never targeted.
|
||||
this.runtimes.delete(id);
|
||||
expected.child.kill();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user