mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
PVF: ensure job processes are cleaned up, add tests (#2643)
Fixes a potential memory leak. `PR_SET_PDEATHSIG` is used to terminate children when the parent dies. Note that this is subject to a race. There seems to be a raceless alternative [here](https://stackoverflow.com/a/42498370/6085242), but the concern is small enough that a bit more complexity doesn't seem worth it. Left a bit more info in the code comment.
This commit is contained in:
@@ -277,6 +277,15 @@ fn handle_child_process(
|
||||
params: Vec<u8>,
|
||||
execution_timeout: Duration,
|
||||
) -> ! {
|
||||
// Terminate if the parent thread dies. Parent thread == worker process (it is single-threaded).
|
||||
//
|
||||
// RACE: the worker may die before we install the death signal. In practice this is unlikely,
|
||||
// and most of the time the job process should terminate on its own when it completes.
|
||||
#[cfg(target_os = "linux")]
|
||||
nix::sys::prctl::set_pdeathsig(nix::sys::signal::Signal::SIGTERM).unwrap_or_else(|err| {
|
||||
send_child_response(&mut pipe_write, Err(JobError::CouldNotSetPdeathsig(err.to_string())))
|
||||
});
|
||||
|
||||
gum::debug!(
|
||||
target: LOG_TARGET,
|
||||
worker_job_pid = %process::id(),
|
||||
|
||||
Reference in New Issue
Block a user