Skip to content

Commit

Permalink
Don't call unref on the timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser committed Jul 19, 2021
1 parent 7a27544 commit 4538a2d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/apollo-server/src/stoppable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,30 @@ export function makeHttpServerStopper(
await new Promise<void>((resolve) => setImmediate(resolve));
stopped = true;

let timeout: NodeJS.Timeout | null = null;
// Soon, hard-destroy everything.
if (stopGracePeriodMillis < Infinity) {
// FIXME don't do unref
setTimeout(() => {
timeout = setTimeout(() => {
gracefully = false;
reqsPerSocket.forEach((_, socket) => socket.end());
// (FYI, when importing from upstream, not sure why we need setImmediate
// here.)
setImmediate(() => {
reqsPerSocket.forEach((_, socket) => socket.destroy());
});
}, stopGracePeriodMillis).unref();
}, stopGracePeriodMillis);
}

// Close the server and create a Promise that resolves when all connections
// are closed. Note that we ignore any error from `close` here.
const closePromise = new Promise<void>((resolve) =>
server.close(() => resolve()),
server.close(() => {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
resolve();
}),
);

// Immediately close any idle sockets.
Expand Down

0 comments on commit 4538a2d

Please sign in to comment.