Skip to content

Commit 3e5286b

Browse files
committed
Explicitly close HTTP server to avoid process.exit
Using `process.exit` directly can cause output to stderr/stdout to be truncated, since it [does not wait for output to streams to be sent](https://nodejs.org/api/process.html#process_process_exit_code). This probably isn't an issue here for the PIP service, but it's worth avoiding it since explicitly closing the HTTP server created by express is easy, and will cause the process to quit "naturally", as nothing else is running. We did actually run into this issue in the [fuzzy-tester](pelias/fuzzy-tester#44) and it's a pain to track down.
1 parent 826a4e9 commit 3e5286b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
const app = require('./app')(process.argv[2]);
2+
13
try {
2-
const app = require('./app')(process.argv[2]);
34
const port = ( parseInt(process.env.PORT) || 3102 );
45

56
app.listen(port, () => {
@@ -8,6 +9,6 @@ try {
89

910
} catch (err) {
1011
console.error(err);
11-
process.exit(1);
12-
12+
process.exitCode = 1;
13+
app.close();
1314
}

0 commit comments

Comments
 (0)