process icon indicating copy to clipboard operation
process copied to clipboard

Don't attach finalizers to Handles in CommunicationHandle API

Open sheaf opened this issue 1 year ago • 1 comments

We are now careful to not attach any finalizers to Handles when creating pipes for inter-process communication on Unix systems. Instead, the handles are closed manually.

The finalizers were causing problems in situations such as the following:

  • the parent creates a new pipe, e.g. pipe2([7,8]),
  • the parent spawns a child process, and lets FD 8 be inherited by the child,
  • the parent closes FD 8 (as it should),
  • the parent opens FD 8 for some other purpose, e.g. for writing to a file,
  • the finalizer for the Handle wrapping FD 8 runs, closing FD 8, even though it is now in use for a completely different purpose.

This PR does not include a test, as the above bug is a bit difficult to trigger. My reproducer for this bug was a test in the cabal-install testsuite; I can confirm that the bug no longer occurs with this patch.

This PR bumps the process version to 1.6.21.0. After releasing it on Hackage, I would also recommend deprecating 1.6.20.0.

sheaf avatar Jul 25 '24 12:07 sheaf

This seems sensible!

tomjaguarpaw avatar Jul 25 '24 16:07 tomjaguarpaw

Yes, this seems like a reasonable approach.

bgamari avatar Aug 08 '24 13:08 bgamari