You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add serverWillStop lifecycle hook; call stop() on signals by default
Fixes#4273.
This PR adds a serverWillStop plugin lifecycle hook. The `serverWillStop` hook
is on an object optionally returned from a `serverWillStart` hook, similar to
`executionDidStart`/`executionDidEnd`.
ApolloServerPluginOperationRegistry uses this to stop its agent.
The code that installs SIGINT and SIGTERM handlers unless disabled with
`handleSignals: false` is hoisted from EngineReportingAgent to ApolloServer
itself and renamed to `stopOnTerminationSignals` as a new ApolloServer
option. The new implementation also skips installing the signals handlers by
default if NODE_ENV=test or if you don't appear to be running in Node (and we
update some tests that explicitly set other NODE_ENVs to set handleSignals:
false).
The main effect on existing code is that on one of these signals, any
SubscriptionServer and ApolloGateway will be stopped in addition to any
EngineReportingAgent.
(This commit adds new documentation for `stopOnTerminationSignals` to the API
reference but does not change the documentation of
`EngineReportingOptions.handleSignals` on that page because a later commit in
this PR removes that section entirely.)
Copy file name to clipboardExpand all lines: docs/source/api/apollo-server.md
+21
Original file line number
Diff line number
Diff line change
@@ -289,6 +289,27 @@ Provide this function to transform the structure of GraphQL response objects bef
289
289
<tr>
290
290
<tdcolspan="2">
291
291
292
+
**Lifecycle options**
293
+
</td>
294
+
</tr>
295
+
296
+
<tr>
297
+
<td>
298
+
299
+
###### `stopOnTerminationSignals`
300
+
301
+
`Boolean`
302
+
</td>
303
+
<td>
304
+
305
+
By default (when running in Node and when the `NODE_ENV` environment variable does not equal `test`), ApolloServer listens for the `SIGINT` and `SIGTERM` signals and calls `await this.stop()` on itself when it is received, and then re-sends the signal to itself so that process shutdown can continue. Set this to false to disable this behavior, or to true to enable this behavior even when `NODE_ENV` is `test`. You can manually invoke `stop()` in other contexts if you'd like. Note that `stop()` does not run synchronously so it cannot work usefully in an `process.on('exit')` handler.
0 commit comments