Ray's Knowledge Base
Unlock

A vfork child's _exit or close changed the parent's dftracer state

PitfallVerified 12 Oct 2026Holds project: dftracer
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

After a vfork child called _exit, the parent's later events were all missing. After a vfork child called close(fd), the parent's later write on that fd was not traced.

Cause#

A vfork child shares the parent's memory, and dftracer does not hook vfork, so no atfork re-init runs. The child's _exit wrapper ran dft_finalize, which set the shared stop flag. The child's close wrapper cleared the shared fd table slot, but the parent's fd stayed open. CPython's _posixsubprocess uses vfork and calls close, close_range or _exit in the child.

Fix#

POSIXDFTracer::in_vfork_child() compares the getpid syscall with the logger's process_id (set by update_log_file, also after a fork re-init). When they differ, exit, _exit, close_range, closefrom, trace() and remove_trace() do nothing extra. The process_id must start at -1 and the check needs owner > 0, because the logger is active before the log file is set.

Evidence#

test_more_io (vfork child does dup2, close, close_range, _exit, then the parent writes) failed on glibc 2.34 with every later event missing, and passes after the fix on glibc 2.28 and 2.34.

Also found by searching

  • dftracer loses all events in the parent after a subprocess
  • _exit in a vfork child finalizes the parent tracer
  • python subprocess vfork child closes fds and the parent stops tracing