closeWithDeadline called graceful() directly inside the Promise executor. A graceful path that threw before returning its promise escaped the executor, so the close() that serveDeno and serveBun return rejected on the spot. The deadline timer had already been armed and nothing cleared it, so it later fired anyway: it logged a timeout and forced a server whose close() had already given up.
graceful() now runs inside Promise.resolve().then(), so a synchronous throw becomes a rejection and takes the path a rejection already took: the shutdown ends, close() resolves, and the timer is cleared.
Note on the expected behaviour: the issue body says the throw should not skip "the deadline and the forced close". This change follows the issue's own suggested fix and the existing contract in the code comment (a graceful path that rejects ends the shutdown at once, without forcing). If a sync throw should instead wait out the deadline and force, that also changes what an async rejection does, and belongs in its own change.
Test: test/close-deadline.test.ts. On develop it fails with "promise rejected 'Error: sync boom' instead of resolving". It also checks that neither onTimeout nor force runs after the deadline has passed.
Fixes GitHub #47.
closeWithDeadline called graceful() directly inside the Promise executor. A graceful path that threw before returning its promise escaped the executor, so the close() that serveDeno and serveBun return rejected on the spot. The deadline timer had already been armed and nothing cleared it, so it later fired anyway: it logged a timeout and forced a server whose close() had already given up.
graceful() now runs inside Promise.resolve().then(), so a synchronous throw becomes a rejection and takes the path a rejection already took: the shutdown ends, close() resolves, and the timer is cleared.
Note on the expected behaviour: the issue body says the throw should not skip "the deadline and the forced close". This change follows the issue's own suggested fix and the existing contract in the code comment (a graceful path that rejects ends the shutdown at once, without forcing). If a sync throw should instead wait out the deadline and force, that also changes what an async rejection does, and belongs in its own change.
Test: test/close-deadline.test.ts. On develop it fails with "promise rejected 'Error: sync boom' instead of resolving". It also checks that neither onTimeout nor force runs after the deadline has passed.
Verified: lint (0 errors), format:check, typecheck, complexity:check, npm test (1162 passed, 107 files), test:deno (63 passed), test:bun (52 passed), test:edge (3/3 PASS).
closeWithDeadline called graceful() directly inside the Promise
executor. A graceful path that threw before returning its promise
escaped the executor, so the close() that serveDeno and serveBun
return rejected on the spot. The deadline timer had already been armed
and nothing cleared it, so it later fired anyway: it logged a timeout
and forced a server whose close() had already given up.
graceful() now runs inside Promise.resolve().then(), so a synchronous
throw becomes a rejection and takes the same path one already took: the
shutdown ends, close() resolves, and the timer is cleared.
GitHub #47.
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 #47.
closeWithDeadline called graceful() directly inside the Promise executor. A graceful path that threw before returning its promise escaped the executor, so the close() that serveDeno and serveBun return rejected on the spot. The deadline timer had already been armed and nothing cleared it, so it later fired anyway: it logged a timeout and forced a server whose close() had already given up.
graceful() now runs inside Promise.resolve().then(), so a synchronous throw becomes a rejection and takes the path a rejection already took: the shutdown ends, close() resolves, and the timer is cleared.
Note on the expected behaviour: the issue body says the throw should not skip "the deadline and the forced close". This change follows the issue's own suggested fix and the existing contract in the code comment (a graceful path that rejects ends the shutdown at once, without forcing). If a sync throw should instead wait out the deadline and force, that also changes what an async rejection does, and belongs in its own change.
Test: test/close-deadline.test.ts. On develop it fails with "promise rejected 'Error: sync boom' instead of resolving". It also checks that neither onTimeout nor force runs after the deadline has passed.
Verified: lint (0 errors), format:check, typecheck, complexity:check, npm test (1162 passed, 107 files), test:deno (63 passed), test:bun (52 passed), test:edge (3/3 PASS).
25007d11b9to51fa7c1a88