Skip to content

Commit 7abda34

Browse files
committed
readme updates for new options and a few usage details
1 parent ec93e98 commit 7abda34

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ $ npm install express-graceful-exit
1515

1616
v0.X.X versions are backwards API compatible, with these minor behavior changes:
1717
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.
2019

2120
## Usage
2221

@@ -33,6 +32,9 @@ var express = require('express');
3332
var app = express();
3433
var gracefulExit = require('express-graceful-exit');
3534

35+
var server = app.listen(port)
36+
37+
gracefulExit.init(server) // use init() if configured to exit the process after timeout
3638
app.use(gracefulExit.middleware(app));
3739
````
3840

@@ -45,7 +47,7 @@ This function tells express to accept no new requests and gracefully closes the
4547
process.on('message', function(message) {
4648
if (message === 'shutdown') {
4749
gracefulExit.gracefulExitHandler(app, server, {
48-
socketio: app.settings.socketio
50+
<see options below>
4951
});
5052
}
5153
});
@@ -66,11 +68,12 @@ The following options are available:
6668
__log__ | Print status messages and errors to the logger | false
6769
__logger__ | Function that accepts a string to output a log message | console.log
6870
__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
7075
__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)
7477
__socketio__ | An instance of `socket.io`, used to close all open connections after timeout | none
7578
__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
7679

@@ -79,11 +82,8 @@ The following options are available:
7982
To gracefully exit this module does the following things:
8083

8184
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
8787
4. Once the server fully disconnects or the hard exit timer runs
8888
1. If all in-flight requests have resolved and/or disconnected, the exit handler returns `0`
8989
2. OR if any connections remain after `suicideTimeout` ms, the handler returns `1`

0 commit comments

Comments
 (0)