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

Fix incorrect exitcode in SIGTERM and SIGINT. #6215

Merged
merged 4 commits into from
Oct 24, 2023
Merged

Conversation

asdacap
Copy link
Contributor

@asdacap asdacap commented Oct 23, 2023

  • Long overdue fix on incorrect exit code on sigterm/sigint.
  • On POSIX, when given SIGTERM/SIGINT, the application should exit with a specific exit code instead of 0.
  • Without this, a script may not behave as expected. For example, if I have a script something like this, which sync, then remove the directory then sync again, on the first nethermind run, when I ctrl-c, I would expect it to stop the whole script. Instead, it remove the directory and start the second run.
nethermind --Sync.ExitOnSynced true
rm -rf thedir
nethermind --Sync.ExitOnSynced true

Changes

  • Return proper exit code.
  • Also consolidate the various exit signal.

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

  • On linux SIGTERM: ✔️
  • On linux SIGINT: ✔️
  • On mac SIGTERM: ✔️
  • On windows: ✔️
  • Exit after sync should have code 0: ✔️

@asdacap asdacap marked this pull request as ready for review October 23, 2023 08:11
@@ -80,7 +80,8 @@ public async Task StartAsync()
}
if (_exposePort is not null)
{
IMetricServer metricServer = new KestrelMetricServer(_exposePort.Value);
// KestrelMetricServer intercept SIGTERM causing exitcode to be incorrect
IMetricServer metricServer = new MetricServer(_exposePort.Value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any implications because of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm guessing its a bit spower compared to kestral. Metrics seems to still works.

Copy link
Member

Choose a reason for hiding this comment

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

It disables non system grafana metrics for Windows 😢

As it uses HttpListener and you need to explicitly give it permissions (outside in OS) to listen on that port or run in Admin mode.

Perhaps switch on OS as I assume Windows isn't paying attention to SIGTERM?

Copy link
Member

Choose a reason for hiding this comment

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

@asdacap asdacap merged commit 2c73638 into master Oct 24, 2023
61 checks passed
@asdacap asdacap deleted the fix/incorrect-exitcode branch October 24, 2023 01:43
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