TeardownRegistry.run set a drained flag and returned at once to any later caller. Teardown ran once, but a second close() made while the first was still awaiting its callbacks resolved straight away, so a signal handler and a test hook closing together could move on with a database still open. This reached every close path: app.close() with or without a listen()ed server, and serveDeno/serveBun, which hand over to app.close().
The registry now keeps the promise of the teardown it started and returns it to every caller. Callbacks still run once, and each caller resolves only after they finish, within its own runTeardown budget. The drain window and closeApp needed no change: the health drain already shares one window, and a second server.close() waits for the same 'close' event. close() after a failed listen() (#138) still has no server and only runs teardown; its tests pass unchanged.
Tests: a registry-level test in test/lifecycle.test.ts and an app-level one in test/teardown.test.ts (two concurrent app.close() on a listen()ed app with a slow onShutdown). Both failed on develop with the second caller resolving before 'torn down'.
Fixes GitHub #45.
TeardownRegistry.run set a `drained` flag and returned at once to any later caller. Teardown ran once, but a second close() made while the first was still awaiting its callbacks resolved straight away, so a signal handler and a test hook closing together could move on with a database still open. This reached every close path: app.close() with or without a listen()ed server, and serveDeno/serveBun, which hand over to app.close().
The registry now keeps the promise of the teardown it started and returns it to every caller. Callbacks still run once, and each caller resolves only after they finish, within its own runTeardown budget. The drain window and closeApp needed no change: the health drain already shares one window, and a second server.close() waits for the same 'close' event. close() after a failed listen() (#138) still has no server and only runs teardown; its tests pass unchanged.
Tests: a registry-level test in test/lifecycle.test.ts and an app-level one in test/teardown.test.ts (two concurrent app.close() on a listen()ed app with a slow onShutdown). Both failed on develop with the second caller resolving before 'torn down'.
Verified: lint (0 errors), format:check, typecheck, complexity:check, npm test (1162 passed), test:deno (63 passed), test:bun (52 passed), test:edge (PASS).
TeardownRegistry.run set a `drained` flag and returned at once to any
later caller. That kept teardown from running twice, but a second
close() made while the first was still awaiting its callbacks resolved
straight away. A signal handler and a test hook closing together could
then move on with a database the first call had not closed yet. This
reached every close path: app.close() with or without a listen()ed
server, and serveDeno/serveBun, which hand over to app.close().
The registry now keeps the promise of the teardown it started and
returns it to every caller, so the callbacks still run once and each
caller resolves only after they finish, within its own runTeardown
budget. The drain window and closeApp needed no change: the health
drain already shares one window, and a second server.close() waits for
the same 'close' event. close() after a failed listen() still has no
server and only runs teardown.
GitHub #45.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Fixes GitHub #45.
TeardownRegistry.run set a
drainedflag and returned at once to any later caller. Teardown ran once, but a second close() made while the first was still awaiting its callbacks resolved straight away, so a signal handler and a test hook closing together could move on with a database still open. This reached every close path: app.close() with or without a listen()ed server, and serveDeno/serveBun, which hand over to app.close().The registry now keeps the promise of the teardown it started and returns it to every caller. Callbacks still run once, and each caller resolves only after they finish, within its own runTeardown budget. The drain window and closeApp needed no change: the health drain already shares one window, and a second server.close() waits for the same 'close' event. close() after a failed listen() (#138) still has no server and only runs teardown; its tests pass unchanged.
Tests: a registry-level test in test/lifecycle.test.ts and an app-level one in test/teardown.test.ts (two concurrent app.close() on a listen()ed app with a slow onShutdown). Both failed on develop with the second caller resolving before 'torn down'.
Verified: lint (0 errors), format:check, typecheck, complexity:check, npm test (1162 passed), test:deno (63 passed), test:bun (52 passed), test:edge (PASS).
e6f6f90cc2to212d2fa5c4