Pull requests

#89 Merged
Deleted repository
default (9d3a0295edbe)
scons/SCons SCons

Stop leaking of filehandles to child processes by closing on fork.

  1. Tom Tanner

This adds some code to close all filehandles but for stdin/out/err after a fork, otherwise file handles get leaked to child processes, which is somewhat of an issue, especially with threading.

  • Learn about pull requests

Comments (4)

  1. Gary Oberbrunner

    This is good; I've had issues like this in the past. How could we test this? Open a file in the SCons process and then in the invoked command make sure that the only open file handles are 0,1,2? How did you run across this?

  2. Tom Tanner author

    Part of our build runs the purify memory (ab)usage diagnostic tool and that prints the number of file handles open on exit. My "i am too scared to submit this" system for stopping the output interleaving opens (potentially) loads of filehandles (1 per thread) and occasionally the diagnostic was triggering and causing the build to fail.

    Some potentially contentious I discovered coding the test is that you can only use fork_spawn or piped_fork_spawn if you need this check as you need to close the file handles after forking. Or the whole boiling lot could be rewritten using subprocess and leave it up to the lower levels to be efficient.

    Having said which I just realised scons 2.3 requires at least python 2.4 so I suppose there's no real harm in doing that?

  3. Tom Tanner author

    This replaces all the posix forking/shell/system calls with calls to subprocess.Popen. It simplifies the code considerably, and makes it trivial to close all the file handles