Skip to content

Standard exit code when shutdown via signal#6852

Closed
mprimi wants to merge 1 commit intomainfrom
marco/exit-code
Closed

Standard exit code when shutdown via signal#6852
mprimi wants to merge 1 commit intomainfrom
marco/exit-code

Conversation

@mprimi
Copy link
Copy Markdown
Contributor

@mprimi mprimi commented Apr 30, 2025

State:
🟧 Code: POC for early feedback
🟥 Tests: missing


When receiving , exit with code 128+.

Pros:

  • Implement de-facto convention
  • Easier integration for any tool/script that expects this convention
  • Easier investigationof "why did server shutdown?" mystery scenarios

Cons:

  • May break some existing integration/tools/script (Hyrum's Law)

Sources:


Behavior without this change:

  • Exit 1 in case of error
  • Exit 0 in case of signal

Target behavior:

  • Exit 1 in case of error
  • Exit 128+signal in case of signal and no shutdown errors
  • Exit 1 in error during shutdown as a result of signal

Signed-off-by: Marco Primi marco@nats.io

When receiving <signal>, exit with code 128+<signal>.

Pros:
 - Implement de-facto convention
 - Easier integration for any tool/script that expects this convention
 - Easier investigation of "why did server shutdown?" mystery scenarios

Cons:
 - May break some existing integration/tools/script (Hyrum's Law)

Sources:
 - https://tldp.org/LDP/abs/html/exitcodes.html
 - https://en.wikipedia.org/wiki/Exit_status#Shell_and_scripts
 - https://www.baeldung.com/linux/status-codes#fatal-error-signal
@mprimi
Copy link
Copy Markdown
Contributor Author

mprimi commented May 2, 2025

Closing after receiving feedback.

Current behavior is fine as-is. Exit with zero as a result of signal is an appropriate behavior for a long-running service.
Carrying a bit more info into the exit code does not justify the risk of breakage and churn the change would create.
For example service-managers like systemd or K8s controllers may restart due to "restart on error" policies.

@mprimi mprimi closed this May 2, 2025
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.

1 participant