Unix: Start notifier thread in Tcl_InitNotifier again if process id changed due to fork1
- Apache starts one process and starts a TCL interpreter
- Users have the ability to execute commands now. For the huge FlightAware website, it was written, that loading packages now, instead in step 4, saves 40 minuites of time.
- Apache forks this process to worker processes including the initialized TCL interpreter. The Notifier Thread required for fileevent is not present in the new process.
- Users have the possibility to do per process initialisation here, like data base open etc.
- If a page is requested, an interpreter in a worker process is called.
The issue is, that fileevents do not fire any more, as there is only one notifier thread in the first process. The notifier thread is invoked by all processes as the anonymous pipe is still active but has no access to shared memory and file handlers of the forked processes.
The idea is to modify the exposed procedure Tcl_InitNotifier to:
- Check, if it was forked, e.g. if the process id changed
- If so, close the connection to the pipe and start a new notifier thread.
Then, Tcl_InitNotifier may be called after the fork and anything is working again...
The current version of Tcl_InitNotifier only creates the thread on the very first call and thus does not recreate after the fork.
Some web pointers:
7cc5639087Closed ticket [1306694fff]: Sockets are not working in the child processes plus 4 other changes ticket2026-10-21 10:03:37e733a91cdbTcl_InitNotifier: Bug [a0bc856dcd]. Start notifier thread again if we were forked, to solve Rivet bug 55153 check-in2013-08-01 12:54:1602909e227fTcl_InitNotifier: Bug [a0bc856dcd]. Start notifier thread again if we were forked, to solve Rivet bug 55153 check-in2013-08-01 12:38:0430ab3e0fb0Start notifier thread again if we were forked, to solve Rivet bug 55153 - RFE [a0bc856dcd] check-in2013-07-17 16:02:36
RFE -> Bug
Rebased [6f69bbba43] to core-8-5-branch, and added "testfork" test command to be used in test-case.
The added test file passes only on a patched Tcl and not on Tcl 8.5 branch.
With the patch, test "iocmd.tf-32.1" waits infinitely but does not on Tcl 8.5 branch.
Thus, the patch still has issues.
My system:
- Linux CentOS x86_64
The stall of test "iocmd.tf-32.1" is fixed by Jan.
Tested by Jan on Cygwin
Tested on CentOS x86_64 with and without threaded:
- no test suite failures while new test always ran
- practical test within Rivet ok
Closed, included in tcl 8.5.15 and tcl 8.6.1 Thank you all, Harald