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
v0.X.X versions are backwards API compatible, with these minor behavior changes:
17
17
1. Process exit is called in a `setTimeout` block from v0.2.0 forward, so the timing is slightly different between v0.1.0 to v0.2.x+.
18
-
2. After exit was triggered, incoming requests were mismanaged prior to v0.5.0.
19
-
As of v0.5.0 incoming requests are dropped cleanly by default and have even better options available, such as responding with a custom error.
18
+
2. After exit was triggered, incoming requests were mismanaged prior to v0.5.0. <br> As of v0.5.0 incoming requests are dropped cleanly by default, with new options such as responding with a custom error and/or performing one last request per connection.
20
19
21
20
## Usage
22
21
@@ -33,6 +32,9 @@ var express = require('express');
33
32
var app =express();
34
33
var gracefulExit =require('express-graceful-exit');
35
34
35
+
var server =app.listen(port)
36
+
37
+
gracefulExit.init(server) // use init() if configured to exit the process after timeout
36
38
app.use(gracefulExit.middleware(app));
37
39
````
38
40
@@ -45,7 +47,7 @@ This function tells express to accept no new requests and gracefully closes the
45
47
process.on('message', function(message) {
46
48
if (message ==='shutdown') {
47
49
gracefulExit.gracefulExitHandler(app, server, {
48
-
socketio:app.settings.socketio
50
+
<see options below>
49
51
});
50
52
}
51
53
});
@@ -66,11 +68,12 @@ The following options are available:
66
68
__log__ | Print status messages and errors to the logger | false
67
69
__logger__ | Function that accepts a string to output a log message | console.log
68
70
__callback__ | Optional function that is called with the exit status code once express has shutdown, gracefully or not <br> Use in conjunction with `exitProcess: false` when the caller handles process shutdown | no-op
69
-
__exitProcess__ | If true, the module calls `process.exit()` when express has shutdown, gracefully or not | true
71
+
__performLastRequest__ | Process the first request received per connection after exit starts, and include a connection close header for callers and load balancers. <br> `false` is the existing behavior, deprecated as of v0.5.0 | false
72
+
__errorDuringExit__ | Respond to incoming requests with an error instead of silently dropping them. <br> `false` is the existing behavior, deprecated as of v0.5.0 | false
73
+
__getRejectionError__ | Function returning rejection error for incoming requests during graceful exit | `function () { return new Error('Server unavailable, no new requests accepted during shutdown') }`
74
+
__exitProcess__ | If true, the module calls `process.exit()` when express has shutdown, gracefully or not | true
70
75
__exitDelay__ | Wait timer duration in the final internal callback (triggered either by gracefulExitHandler or the hard exit handler) if `exitProcess: true` | 10ms
71
-
__respondDuringExit__ | Respond to incoming requests with an error (instead of silently dropping them) | false (see below)
72
-
__unavailableError__ | Function returning rejection error for incoming requests during graceful exit | `function () { return new Error('Server unavailable, no new requests accepted during shutdown') }`
73
-
__suicideTimeout__ | How long to wait before giving up on graceful shutdown, then returns exit code of 1 | 2m 10s (130s)
76
+
__suicideTimeout__ | How long to wait before giving up on graceful shutdown, then returns exit code of 1 | 2m 10s (130s)
74
77
__socketio__ | An instance of `socket.io`, used to close all open connections after timeout | none
75
78
__force__ | Instructs the module to forcibly close sockets once the suicide timeout elapses. <br> For this option to work you must call `gracefulExit.init(server)` when initializing the HTTP server | false
76
79
@@ -79,11 +82,8 @@ The following options are available:
79
82
To gracefully exit this module does the following things:
80
83
81
84
1. Closes the http server so no new connections are accepted
82
-
2. Closes existing connections that use the Keep-Alive header</br>
83
-
The HTTP status code of 502 is returned, so nginx, ELB, etc will try with an active server</br>
84
-
If `respondDuringExit` is set to true, a response is sent with `Connection: close`
85
-
3. If a socket.io instance is passed in the options, all connected clients are immediately disconnected (socket.io v0.X through v1.4.x support)</br>
86
-
The client should have code to reconnect on disconnect
85
+
2. Sets connection close header for Keep-Alive connections, if configured for responses</br> The HTTP status code of 502 is returned, so nginx, ELB, etc will try with an active server</br> If `errorDuringExit` and/or `performLastRequest` are set to true, a response is sent with a `Connection: close` header
86
+
3. If a socket.io instance is passed in the options, all connected clients are immediately disconnected (socket.io v0.X through v1.4.x support)</br> The client should have code to reconnect on disconnect
87
87
4. Once the server fully disconnects or the hard exit timer runs
88
88
1. If all in-flight requests have resolved and/or disconnected, the exit handler returns `0`
89
89
2. OR if any connections remain after `suicideTimeout` ms, the handler returns `1`
0 commit comments