Skip to content

Commit

Permalink
Explicitly close HTTP server to avoid process.exit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
orangejulius committed Oct 24, 2017
1 parent 826a4e9 commit 3e5286b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const app = require('./app')(process.argv[2]);

try {
const app = require('./app')(process.argv[2]);
const port = ( parseInt(process.env.PORT) || 3102 );

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

} catch (err) {
console.error(err);
process.exit(1);

process.exitCode = 1;
app.close();
}

0 comments on commit 3e5286b

Please sign in to comment.