fix(shutdown): treat a graceful close that throws synchronously as a rejection
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>
This commit is contained in:
3 files changed
+29
-2
No files matched your search
@@ -44,7 +44,9 @@ export function closeWithDeadline(
|
||||
};
|
||||
|
||||
// A graceful path that rejects still has to end the shutdown: the deadline covers a slow
|
||||
// close, not a broken one, and leaving close() pending forever is the worse failure.
|
||||
void graceful().then(finish, finish);
|
||||
// close, not a broken one, and leaving close() pending forever is the worse failure. Called
|
||||
// inside `then` so a graceful path that throws before returning its promise counts as a
|
||||
// rejection too, rather than rejecting close() and leaving the timer to force a closed server.
|
||||
void Promise.resolve().then(graceful).then(finish, finish);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user