Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Unix: Start notifier thread in Tcl_InitNotifier again if process id changed due to fork1

Closed / Accepteda0bc856dcde485c71fc657fc9387842e41b6449dCreated 13 years agoUpdated 13 years ago
Descriptionwiki2013-07-17 15:23:55
Rivet, the Apache tcl module, does the following:
  1. Apache starts one process and starts a TCL interpreter
  2. 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.
  3. 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.
  4. Users have the possibility to do per process initialisation here, like data base open etc.
  5. 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:

  1. Check, if it was forked, e.g. if the process id changed
  2. 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:

Referenced by4
  • 7cc5639087Closed ticket [1306694fff]: Sockets are not working in the child processes plus 4 other changes ticket2026-10-21 10:03:37
  • e733a91cdbTcl_InitNotifier: Bug [a0bc856dcd]. Start notifier thread again if we were forked, to solve Rivet bug 55153 check-in2013-08-01 12:54:16
  • 02909e227fTcl_InitNotifier: Bug [a0bc856dcd]. Start notifier thread again if we were forked, to solve Rivet bug 55153 check-in2013-08-01 12:38:04
  • 30ab3e0fb0Start notifier thread again if we were forked, to solve Rivet bug 55153 - RFE [a0bc856dcd] check-in2013-07-17 16:02:36
jan.nijtmanswiki2013-07-21 15:54:33

RFE -> Bug

Rebased [6f69bbba43] to core-8-5-branch, and added "testfork" test command to be used in test-case.

oehharwiki2013-07-22 08:52:12

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

oehharwiki2013-07-22 10:58:59

The stall of test "iocmd.tf-32.1" is fixed by Jan.

oehharwiki2013-07-22 12:15:59

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

oehharplain2013-09-17 06:49:31
Closed, included in tcl 8.5.15 and tcl 8.6.1
Thank you all,
Harald
Log in (anonymous is fine) to add a comment.