Tk Source Code

View Ticket
Login
Ticket UUID: 1715716
Title: window-2.9 deadlocks threaded Tk
Type: Bug Version: obsolete: 8.6b1
Submitter: das Created on: 2007-05-09 13:39:20
Subsystem: 69. Events Assigned To: dgp
Priority: 9 Immediate Severity: Minor
Status: Pending Last Modified: 2017-12-06 15:57:51
Resolution: Fixed Closed By: nobody
    Closed on: 2015-10-26 08:20:56
Description:
The test window-2.9 deadlocks threaded TkX11 and TkAqua (only generic code appears to be involved). Backtrace from TkX11 attached.
The test succeeds in the unthreaded build.

window-2.9 runs the following in a subprocess:
        toplevel .t1
        toplevel .t2
        update
        bind .t2 <Destroy> {puts "Destroy .t2" ; exit 1}
        bind .t1 <Destroy> {puts "Destroy .t1" ; exit 0}
        destroy .t2

the deadlock occurs because Tcl_Finalize() is entered recursively, first from the [exit] in the .t2 <Destroy> handler, where it calls TkFinalizeThread(), which destroys all windows and causes the .t1 <Destroy> handler to fire, leading to a nested [exit] and deadlock on TclpInitLock() in Tcl_Finalize().
User Comments: dgp added on 2017-12-06 15:57:51:
Hangs in --enable-symbols build of Tk 8.6.8rc

dgp added on 2017-03-30 16:58:46:
.....and now I cannot repeat it again.  Something
very particular must be at work here.

dgp added on 2017-03-29 20:37:58:
Test is hanging again in 8.6.7 RC branch.

dgp added on 2013-03-26 20:41:40:
This is fixed in 8.6.  Presumably a consequence
of the reworking of Tcl finalization.  

Removed the constraint from the test.

Still buggy on older branches.  Seems destined 
to be a forever "Won't Fix" there.

das added on 2008-12-29 23:49:01:
now added a constraint to bypass window-2.9 in threaded builds

raising prio, would be desirable to resolve the deadlock from nested invocations of Tcl_Finalize() for 8.6

dgp added on 2007-05-10 05:16:56:
Logged In: YES 
user_id=80530
Originator: NO


I don't have all the details
straight in my head anymore without
digging into the logs for a good
review, but I do recall that we've
gotten Tk finalization matters wrong
at least a couple of different ways
already, so much care and much testing
are in order as we move forward with
this one.

das added on 2007-05-10 04:26:14:
Logged In: YES 
user_id=90580
Originator: YES

indeed a dup of 740570, apologies.

The analysis there and in 870281 seem to look at the wrong process though, the backtrace here is from the subprocess where the snippet above runs (which is where the deadlock occurs).
The hang can be reproduced simply by running the code above in a threaded tktest, so there is no involvment of exec/fork/signals as theorized in 740570.

The problem is definitely caused by nested invocation of [exit] from the <Destroy> handlers; not sure how to go about a fix in Tk, DestroyNotify events explicitly ignore TK_ALREADY_DEAD...

The easiest option might be to check inFinalize before setting it in Tcl_Finalize(), or equivalently, to check TclInExit() in Tcl_Exit() before calling Tcl_Finalize(), but I don't understand tcl finalization well enough to know if that would have undesireable effects.

das added on 2007-05-10 04:13:08:
Logged In: YES 
user_id=90580
Originator: YES

indeed a dup of 740570, apologies.

The analysis there and in 870281 seem to look at the wrong process though, the backtrace here is from the subprocess where the snippet above runs (which is where the deadlock occurs).
The hang can be reproduced simply by running the code above in a threaded tktest, so there is no involvment of exec/fork/signals as theorized in 740570.

The problem is definitely caused by nested invocation of [exit] from the <Destroy> handlers; not sure how to go about a fix in Tk, DestroyNotify events explicitly ignore TK_ALREADY_DEAD...

The easiest option might be to check inFinalize before setting it in Tcl_Finalize(), or equivalently, to check TclInExit() in Tcl_Exit() before calling Tcl_Finalize(), but I don't understand tcl finalization well enough to know if that would have undesireable effects.

dgp added on 2007-05-09 20:48:39:
Logged In: YES 
user_id=80530
Originator: NO


Dup. of 740570 ?

das added on 2007-05-09 20:39:21:

File Added - 228503: window-2.9-backtrace.txt

Attachments: