fix(subprocess): prioritize host-exit cleanup listener
This commit is contained in:
@@ -48,7 +48,7 @@ export class LocalSubprocessService extends SubprocessService {
|
|||||||
super(ctx)
|
super(ctx)
|
||||||
ctx.effect(() => {
|
ctx.effect(() => {
|
||||||
const onHostExit = (): void => { this.terminateForHostExit() }
|
const onHostExit = (): void => { this.terminateForHostExit() }
|
||||||
process.on('exit', onHostExit)
|
process.prependListener('exit', onHostExit)
|
||||||
return async () => {
|
return async () => {
|
||||||
try {
|
try {
|
||||||
await this.disposeManagedProcesses()
|
await this.disposeManagedProcesses()
|
||||||
|
|||||||
@@ -21,6 +21,23 @@ function spec(command: string, overrides: Partial<SubprocessSpawnSpec> = {}): Su
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('LocalSubprocessService', () => {
|
describe('LocalSubprocessService', () => {
|
||||||
|
it('places the host-exit finalizer before listeners that predate the service', async () => {
|
||||||
|
const baseline = new Set(process.listeners('exit'))
|
||||||
|
const prior = vi.fn()
|
||||||
|
process.on('exit', prior)
|
||||||
|
const ctx = new Context()
|
||||||
|
const fiber = await ctx.plugin(LocalSubprocessService)
|
||||||
|
try {
|
||||||
|
const listeners = process.listeners('exit')
|
||||||
|
const finalizer = listeners.find(candidate => !baseline.has(candidate) && candidate !== prior)
|
||||||
|
expect(finalizer).toBeTypeOf('function')
|
||||||
|
expect(listeners.indexOf(finalizer!)).toBeLessThan(listeners.indexOf(prior))
|
||||||
|
} finally {
|
||||||
|
process.off('exit', prior)
|
||||||
|
await fiber.dispose()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('keeps the host-exit finalizer active until normal disposal reaches quiescence', async () => {
|
it('keeps the host-exit finalizer active until normal disposal reaches quiescence', async () => {
|
||||||
const before = new Set(process.listeners('exit'))
|
const before = new Set(process.listeners('exit'))
|
||||||
const ctx = new Context()
|
const ctx = new Context()
|
||||||
|
|||||||
Reference in New Issue
Block a user