Skip to content

Configurable wait timeout for process to end and -w SECONDS CLI option#363

Closed
iandennismiller wants to merge 20 commits intorfjakob:masterfrom
iandennismiller:master
Closed

Configurable wait timeout for process to end and -w SECONDS CLI option#363
iandennismiller wants to merge 20 commits intorfjakob:masterfrom
iandennismiller:master

Conversation

@iandennismiller
Copy link

This pull request introduces a new configurable option, -w SECONDS, to control the maximum time earlyoom waits for a killed process to exit. The implementation includes updates to the CLI, input validation, documentation, and associated tests. This change allows users to adjust the wait timeout (default 10 seconds) to better handle processes that take longer to terminate.

New feature: Configurable process wait timeout

  • Added a -w SECONDS command-line option to set the maximum wait time (in seconds) for a killed process to exit, with input validation and a maximum limit of 24 hours (86400 seconds). [1] [2] [3]
  • Updated the poll_loop_args_t struct and related logic to store and use the new kill_wait_timeout_secs value, defaulting to 10 seconds. [1] [2]
  • Modified the process waiting logic in kill_wait to use the user-specified timeout, with overflow protection for the poll loop. [1] [2]

Documentation and testing

  • Updated the documentation (MANPAGE.md) to describe the new -w option and its usage.
  • Added and updated CLI tests to verify correct handling of the -w flag, including invalid values and edge cases.

Internal constants and options

  • Introduced a new constant for the maximum allowed wait timeout and updated the CLI options enum accordingly. [1] [2]

Copilot AI and others added 10 commits February 17, 2026 14:16
Co-authored-by: iandennismiller <90502+iandennismiller@users.noreply.github.com>
…afety

Co-authored-by: iandennismiller <90502+iandennismiller@users.noreply.github.com>
Co-authored-by: iandennismiller <90502+iandennismiller@users.noreply.github.com>
Co-authored-by: iandennismiller <90502+iandennismiller@users.noreply.github.com>
Co-authored-by: iandennismiller <90502+iandennismiller@users.noreply.github.com>
Co-authored-by: iandennismiller <90502+iandennismiller@users.noreply.github.com>
…wait-countdown

Add configurable kill_wait() timeout via -w flag
@rfjakob
Copy link
Owner

rfjakob commented Feb 17, 2026

Hi, what problem does this solve?

@iandennismiller
Copy link
Author

The process I'm monitoring takes longer than 10 seconds to shut down; and if it is terminated forcefully, it results in database corruption.

I need to prevent earlyoom from re-issuing SIGTERM every 10 seconds. Eventually, sending enough SIGTERMs will cause the process to terminate early, which corrupts the database. So, after 100 seconds and the receipt of 10 SIGTERMs, it will exit immediately as if it were SIGKILLed.

With the flag in this PR, I am specifying -w 300 to to throttle how quickly earlyoom sends SIGTERM. The desired outcome is that subsequent SIGTERMs are sent less frequently. In practice, I haven't seen the process take longer than 900 seconds to finish. So for me, a wait time of 5 minutes fits the time scale of my monitored process better than the 10 second interval.

@rfjakob
Copy link
Owner

rfjakob commented Feb 17, 2026

So your process counts SIGTERMs? What process is this?

@iandennismiller
Copy link
Author

go-ethereum

@rfjakob
Copy link
Owner

rfjakob commented Feb 17, 2026

Wow, really https://github.com/ethereum/go-ethereum/blob/3eed0580d4dc40fb15a14e1b0e9fc6985fefbfd7/cmd/utils/cmd.go#L110

@iandennismiller
Copy link
Author

iandennismiller commented Feb 17, 2026

Wow, really https://github.com/ethereum/go-ethereum/blob/3eed0580d4dc40fb15a14e1b0e9fc6985fefbfd7/cmd/utils/cmd.go#L110

Exactly; a bit idiosyncratic but there are non-production situations where it's handy, I suppose.

But for my purposes, I need to work around the 10 SIGTERMS behavior because it's not what I intend.

Copy link
Owner

@rfjakob rfjakob left a comment

Choose a reason for hiding this comment

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

Some small changes, otherwise ok.


int c;
const char* short_opt = "m:s:M:S:kingN:P:dvr:ph";
const char* short_opt = "m:s:M:S:kingN:P:dvr:phw:";
Copy link
Owner

Choose a reason for hiding this comment

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

Please make this --kill-wait instead of -w.

" to 0 to disable completely\n"
" -p set niceness of earlyoom to -20 and oom_score_adj to\n"
" -100\n"
" -w SECONDS max seconds to wait for a process to die (default 10)\n"
Copy link
Owner

Choose a reason for hiding this comment

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

--kill-wait

OOMScoreAdjust=-100
Nice=-20

#### -w SECONDS
Copy link
Owner

Choose a reason for hiding this comment

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

--kill-wait

kill.c Outdated
Comment on lines 273 to 275
if ((unsigned)args->kill_wait_timeout_secs > UINT_MAX / 10u) {
// Cap at maximum to avoid overflow (should never happen in practice)
max_poll_iterations = UINT_MAX;
Copy link
Owner

Choose a reason for hiding this comment

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

Cannot happen. Delete the check.

Copy link
Owner

@rfjakob rfjakob left a comment

Choose a reason for hiding this comment

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

Please rebase to master

@iandennismiller iandennismiller marked this pull request as draft February 17, 2026 21:59
rfjakob and others added 10 commits February 18, 2026 10:20
Currently fails with

	Minimum supported API version is 1.44, please upgrade your client to a newer version.

addnab/docker-run-action#62
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 4.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@v2...v4)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v2...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
As mentioned in issue
rfjakob/earlyoom#358 and README, after
Linux 5.17, OOM sysrq will always kill a process.

This implements an option for trigger the kernel oom killer i.e.
write an `f` to `/proc/sysrq-trigger`. Since the victim cannot be
chosen by earlyoom, some of the features about customized victim
selection won't take effect.
Co-authored-by: iandennismiller <90502+iandennismiller@users.noreply.github.com>
Co-authored-by: iandennismiller <90502+iandennismiller@users.noreply.github.com>
Co-authored-by: iandennismiller <90502+iandennismiller@users.noreply.github.com>
@iandennismiller
Copy link
Author

I am going to change the sequencing of this pull request and re-submit a new one in a bit. The problem is that I merged to master and based the PR on that, when I should have based the PR on the pre-merge branch. It will be simpler for me to cherry-pick the changes into a new branch that's already synced to yours.

@iandennismiller
Copy link
Author

Closing this PR.

Please see #366 for the replacement PR with a cleaner merge path.

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.

4 participants