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

[ re #2944, fix ] Make popen2 be able to not to leak system resources #3170

Merged
merged 2 commits into from
Dec 20, 2023

Conversation

buzden
Copy link
Contributor

@buzden buzden commented Dec 19, 2023

Description

Current implementation of popen2 function introduces in #2944 has slightly different behaviour for POSIX and Windows systems, and, more importantly, it leaves zombie processes on POSIX systems, which, when being run regularly, leads to exhaustiveness of PIDs in a system.

Anyway, leaky and unstable behaviour is not to nice, so I propose the simplest solution I came with. I suggest to make behaviour similar in POSIX and WIndows AND requiring a cleanup call popen2Wait. Roughtly speaking, this is not a much stretch, because for usual popen we already have a pair function pclose with the similar meaning. We can't have direct "closing" analogue for popen2, because moment and order of closing of the file handlers depends on a particular use (unlike popen), so, full cleanup has to be in a series of closings of file handlers and then calling to the newly added function popen2Wait.

Behaviour of the existing (leaky) Idris code that currently uses existing popen2 function remains unchanged with this PR (being run on POSIX systems). So this PR shouldn't break anything.

Alternative solution of the leaking problem was considered (and even mosly implemented in a separate branch). I produces fully detached process which does not produce a zombie in the end, disallowing, however, to get the exit code of this process (at least, easily). But this solution (suddenly) happened to be much more complicated, and, after several attempts to design nicely, I realised that this alternative solution should contain the solution from this PR, so we should first do this before thinking whether we need an ability of detached processes or not.

Pinging @dunhamsteve and @mattpolzin as the original's PR author and main reviewer.

Should this change go in the CHANGELOG?

  • If this is a fix, user-facing change, a compiler change, or a new paper
    implementation, I have updated CHANGELOG.md (and potentially also
    CONTRIBUTORS.md).

This fixes problem of creation the garbage of zombie processes on POSIX
systems. This also makes behaviour of `popen2` identical in Windows,
namely, all resources are freed only when waiting, giving at the same
time an ability to observe the exit code afterwards.
Copy link
Collaborator

@mattpolzin mattpolzin left a comment

Choose a reason for hiding this comment

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

This looks good to me. The test update looks thorough, too.

@dunhamsteve
Copy link
Contributor

Looks good, thanks for taking care of this.

@andrevidela andrevidela merged commit 3502f4a into idris-lang:main Dec 20, 2023
22 checks passed
@buzden buzden deleted the make-able-wait-popen2 branch December 20, 2023 11:42
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.

None yet

4 participants