Skip to content

Commit

Permalink
fix(@apollo/gateway) Call unref on the federated gateway's `s… (apo…
Browse files Browse the repository at this point in the history
…llographql/apollo-server#3105)

* fix(@apollo/gateway) Call `unref` on the federated gateway's `setInterval`.

When the Apollo Gateway is configured in so-called "managed mode", it uses a
`setInterval` timer to periodically check for updates from the Apollo Graph
Manager (also known as Apollo Engine).

However, since the Timer's `unref` method wasn't invoked, the timer would
continue to place tasks on the event loop, even when the server had been
requested to be shutdown.  By calling `unref`, Node.js switches the timer to
an internal timer which doesn't block the event-loop.

While we could alternatively use a `process.on` event to detect when a
shutdown signal had been received and invoke the Gateway's `stop` method
accordingly, this should be sufficient for this particular implementation.
(As opposed to the implementation in `apollo-engine-reporting`  which does
exactly this since it needs to ensure that all queued traces are transmitted
to the cloud prior to process exit.

* Add CHANGELOG.md for apollographql/apollo-server#3105.

Apollo-Orig-Commit-AS: apollographql/apollo-server@73019e9
  • Loading branch information
abernix authored Jul 30, 2019
1 parent 87240c7 commit a576a83
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gateway-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ export class ApolloGateway implements GraphQLService {
);
}
}, 10 * 1000);

// Prevent the Node.js event loop from remaining active (and preventing,
// e.g. process shutdown) by calling `unref` on the `Timeout`. For more
// information, see https://nodejs.org/api/timers.html#timers_timeout_unref.
this.pollingTimer.unref();
}

protected createServices(services: ServiceEndpointDefinition[]) {
Expand Down

0 comments on commit a576a83

Please sign in to comment.