Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add graceful shutdown and error handling #779

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

Octalbyte
Copy link

@Octalbyte Octalbyte commented Dec 25, 2021

This PR adds handling for fatal crashes of any type. Just so you don't have to see a giant error stack on your console.
The feature is turned on by the --no-panic option or by the environment variable NODE_HTTP_SERVER_NO_PANIC.
The output is something like:
image

Relevant issues

Refers partly to #665

What needs to be done:
  • Add switch.
  • Better log file (JSON formatting)
Contributor checklist
  • Provide tests for the changes (unless documentation-only)
  • Documented any new features, CLI switches, etc. (if applicable)
    • Server --help output
    • README.md
    • doc/http-server.1 (use the same format as other entries)
  • The pull request is being made against the master branch
Maintainer checklist
  • Assign a version triage tag
  • Approve tests if applicable

@Octalbyte Octalbyte marked this pull request as draft December 26, 2021 16:40
@Octalbyte
Copy link
Author

Ready for review.

@Octalbyte Octalbyte marked this pull request as ready for review December 27, 2021 15:10
bin/http-server Outdated
@@ -60,12 +64,15 @@ if (argv.h || argv.help) {
' --no-dotfiles Do not show dotfiles',
' --mimetypes Path to a .types file for custom mimetype definition',
' -h --help Print this list and exit.',
' -v --version Print the version and exit.'
' -v --version Print the version and exit.',
' -n --no-panic If error occurs, gracefully shut down and create log file',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure -n is an easy mnemonic here, would only having the long version available be sufficient?

bin/http-server Outdated Show resolved Hide resolved
bin/http-server Outdated
let etime = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')
console.log(colors.green(etime))
console.log(colors.red("Fatal error: ")+ e.code + ": "+e.message)
let fname = ".httpserver-"+etime.split(" ")[0]+"-"+etime.split(" ")[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the log file, could we end it with .log to make it clear what the file is?

@Octalbyte Octalbyte requested a review from thornjad June 11, 2022 14:14
@@ -57,6 +57,10 @@ Default file extension is none is provided.
.BI \-s ", " \-\-silent
Suppress log messages from output.

.TP
.BI \-n ", " \-\-no-panic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the -n needs removing

var argv = require('minimist')(process.argv.slice(2), {
alias: {
tls: 'ssl'
}
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank lines not needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants