Tcl Source Code

View Ticket
Login
Ticket UUID: a0bc856dcde485c71fc657fc9387842e41b6449d
Title: Unix: Start notifier thread in Tcl_InitNotifier again if process id changed due to fork1
Type: Bug Version: 8.6.0
Submitter: oehhar Created on: 2013-07-17 15:23:55
Subsystem: 01. Notifier Assigned To: oehhar
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2013-09-17 06:49:31
Resolution: Accepted Closed By: oehhar
    Closed on: 2013-09-17 06:49:31
Description:

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:

User Comments: oehhar added on 2013-09-17 06:49:31:
Closed, included in tcl 8.5.15 and tcl 8.6.1
Thank you all,
Harald

oehhar added on 2013-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


oehhar added on 2013-07-22 10:58:59:

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


oehhar added on 2013-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


jan.nijtmans added on 2013-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.