Skip to content

Forward termination signals to child process#332

Merged
EdSchouten merged 1 commit intobuildbarn:mainfrom
meroton:forward-signals-to-child
Mar 26, 2026
Merged

Forward termination signals to child process#332
EdSchouten merged 1 commit intobuildbarn:mainfrom
meroton:forward-signals-to-child

Conversation

@oscar-meroton
Copy link
Copy Markdown
Contributor

Commit d2a3a16,
"On Linux, relaunch the current process when running as PID 1 (#311)", relaunches the command in a child process and then waits for it to exit, if the parent process has PID 1. If the command is ran in a container, any termination signal sent to the container is forwarded to the parent process. This unfortunately prevents the persistent state files from being saved to disk if the container is killed, as the child process never receives the shutdown signal.
This commit forwards SIGINT and SIGTERM signals to the child process, which then saves the state files to disk, exits, and triggers a graceful exit in PID 1.

Commit d2a3a16,
"On Linux, relaunch the current process when running as PID 1 (buildbarn#311)",
relaunches the command in a child process and then waits for it to exit,
if the parent process has PID 1. If the command is ran in a container,
any termination signal sent to the container is forwarded to the parent
process. This unfortunately prevents the persistent state files from
being saved to disk if the container is killed, as the child process
never receives the shutdown signal.
This commit forwards `SIGINT` and `SIGTERM` signals to the child
process, which then saves the state files to disk, exits, and triggers
a graceful exit in PID 1.

Co-authored-by: Fredrik Medley <fredrik@meroton.com>
@aspect-workflows
Copy link
Copy Markdown

aspect-workflows bot commented Mar 24, 2026

Test

1 test target passed

Targets
//pkg/blobstore/sharding/integration:integration_test [k8-fastbuild]                 73ms

Total test execution time was 73ms. 29 tests (96.7%) were fully cached saving 5s.

@oscar-meroton
Copy link
Copy Markdown
Contributor Author

@EdSchouten,

  1. Do you have any thoughts on whether to forward any signal, or just the two listed in terminationSignals?
  2. Currently the error from syscall.Kill is not handled, should the program behave differently if an error is returned?

@EdSchouten
Copy link
Copy Markdown
Member

  1. Sticking to the termination signals is all right.
  2. What you have in terms of error handling is also all right!

\o/

@oscar-meroton
Copy link
Copy Markdown
Contributor Author

@EdSchouten Great! Is there anything else or can we go ahead and merge?

@EdSchouten
Copy link
Copy Markdown
Member

Oh sorry. Was waiting for CI to complete, and forgot to merge.

@EdSchouten EdSchouten merged commit d0c6f26 into buildbarn:main Mar 26, 2026
3 checks passed
@oscar-meroton oscar-meroton deleted the forward-signals-to-child branch March 26, 2026 17:09
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.

2 participants