Artifacts Associated With Ticket 3408824fffffffffffffffffffffffffffffffff
Ticket change [ef959412e0] (rid 109020) by dgp on 2011-09-13 17:52:08:
- assignee initialized to: "andreas_kupries"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Working on the tip of the trunk, with a -DPURIFY --disable-shared --enable-symbols build, when I invoke the following multiple times: $ make test-tcl TESTFLAGS="-file ioCmd.test -match iocmd.tf-24.16 -verbose bpste" I get a variety of results. Often the test just succeeds. But sometimes I get a test failure summarized: ---- Result was: {write rc0 ABC} {watch rc0 write} {} BG {write rc0 ABC} BG {finalize rc0} ---- Result should have been (glob matching): {write rc* ABC} {watch rc* write} {} BG {write rc* ABC} ==== iocmd.tf-24.16 FAILED and other times I get segfaults and aborts of various kinds. - foundin initialized to: "obsolete: 8.6b2"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "dgp"
- subsystem initialized to: "24. Channel Commands"
- title initialized to: "iocmd.tf-24.16 unstable w/ -DPURIFY"
- type initialized to: "Bug"
Ticket change [ec9ef2a0db] (rid 103737) by dgp on 2011-09-14 00:56:03:
- icomment:
It's hard to catch the segfaults in a debugger, but the few times I have, they appear to be during thread finalization. I think our "rapid exit without finalize" default mode skips over these failures. So maybe I'm just requesting finalization debugging without realizing it.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [27b172193a] (rid 88564) by dgp on 2011-09-14 00:57:12:
- icomment:
The trouble is that starting from a noisy baseline makes the kind of migrations like the [testthread] -> Thread thing I'm attempting more difficult, because I can't easily see whether I'm breaking things.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [c0474bf12e] (rid 102378) by ferrieux on 2011-09-14 01:17:40:
- icomment:
Yes, the -DPURIFY implies force-finalize. Are you suggesting to make the two orthogonal ? (that's trivial, since ::env(TCL_FINALIZE_ON_EXIT) is already there to explore finalization in production builds.
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [758802e338] (rid 105408) by dgp on 2011-09-14 01:19:41:
- icomment:
No, I'm not suggesting anything. I'm just recording my thoughts as I realize that I'm asking for the solution of something hard, not easy. Solve Thread finalization! Now! Then go have lunch.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [3aee8990b1] (rid 112645) by andreas_kupries on 2011-09-14 01:31:23:
- icomment:
Alexandre, methinks that you misunderstood the 'finalize' in the test result. This is not thread finalization. This is the finalization event send by the machinery for reflected channels when the channel is closed, ordering the Tcl level handler code for the channel to clean itself up. The test itself uses threads to test that the whole machinery works with the channel in thread B and the handler in the thread A, where the channel was created.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [34c44a2d64] (rid 106803) by dgp on 2011-09-14 01:40:18:
- icomment:
I mean both! :) When the test simply fails, aku is correct that it's an issue of variation in the way the channel is closed whether an additional {finalize *} note gets lappended to the expected result. However, when I've managed to captured the segfaults or other aborts, the stack trace has indicated the problem happens during the call to Tcl_FinalizeThread(). - login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [75edcce563] (rid 105479) by dgp on 2011-09-14 01:48:05:
- icomment:
ferrieux, thanks for the reminder about TCL_FINALIZE_ON_EXIT. Testing with that, but in a build without -DPURIFY, I was never able to make the test fail. However, I was able to see a segfault once. These appear to be two different issues with the one test.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [966da30b79] (rid 106324) by ferrieux on 2011-09-14 02:32:27:
- icomment:
Andreas, indeed I was echoing Don's mention of segfaults, since that's exactly the kind of thing that the 2001201 quick-exit reform was meant to avoid :) Now about that extra BG-finalize in the test output: what about replacing [update] with a more deterministic [vwait something], where $something would be conditioned by the presence of the last flushed byte from the sender ?
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [fa8ad50855] (rid 91894) by andreas_kupries on 2011-09-14 04:31:42:
- icomment:
thread/finalize/segfaults - Oh, ok, then the misunderstanding was mine. I am not exactly sure what you wish to condition on, maybe you can can show me a patch ? I was thinking about using vwait as well, although with a timeout via after if the expected data doesn't arrive within a reasonable time frame (say 2 seconds).
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [e8862e7237] (rid 104660) by dgp on 2011-09-17 01:44:05:
- icomment:
On Mac OS X, this test reliably fails even on a non- PURIFY build.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [00554e5bf6] (rid 119303) by dgp on 2011-09-17 03:15:43:
- icomment:
adding "onfinal; " to [foo] body before "note BG" stops the failure observed on OS X
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [9a6ea1babf] (rid 110941) by ferrieux on 2011-09-17 17:11:22:
- icomment:
Instrumenting the unmodified test on entry to both [foo]s: Succeeding case: FOO1:initialize rc0 {read write} FOO1:write rc0 ABC FOO1:watch rc0 write FOO2:write rc0 ABC Failing case: FOO1:initialize rc0 {read write} FOO1:write rc0 ABC FOO1:watch rc0 write FOO2:write rc0 ABC FOO2:finalize rc0 - login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [8285b6d3fd] (rid 117251) by ferrieux on 2011-09-17 17:15:01:
- icomment:
Yes, the previous comment was equivalent with the test output :} But adding "onfinal" merely hides the problem: clearly there's a race condition, the finalize method being randomly called or not. Why ?
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [b8710e15db] (rid 128969) by ferrieux on 2011-09-18 04:13:56:
- icomment:
Note that replacing [update] with [after 200 +vwait] lets the [finalize] occur deterministically. Moreover, all reflected channel handler invocations seem to occur in the main thread, not the spawned-and-reaped one. Is it the intended semantics of [testchannel cut/splice] ?
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [7308304899] (rid 104973) by andreas_kupries on 2011-09-18 07:28:51:
- icomment:
Yes, "testchannel cut/splice" are tcltest's method of moving a channel between threads. The package Thread has the public method, a 'thread transfer' command. Internally both use the same C APIs. For reflected channels specificially we can only move (ownership of) the Channel structures between threads, the Tcl part has to stay behind in the thread the channel was created in, because we do not know what dependencies in terms of code, variables, packages, etc. this part has. When such a separation between the levels happens Events and the Tcl Event Queue are used by the C level to send the necessary instructions to the thread handling the Tcl part instead of invoking the script code on its own, plus mutexes and condition variables to wait and get any results. Everything in tclIORChan.c and tclIORTrans.c which has 'Forward' in the name (regardless of case) is related to this. I would put my eye on the parts interacting with the destruction of threads (cleaning up of structures, events, etc.) as a possible source of the problem.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [6c8e8a8520] (rid 128534) by andreas_kupries on 2011-09-18 07:29:45:
- icomment:
Ok, I hope that helps.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [c3fdcce807] (rid 111767) by ferrieux on 2011-09-18 16:01:35:
- icomment:
Yes it does, thanks for switching the light on :) One side question: when designing this, have you considered the following, simpler alternative: When transferring a RC, in addition to tranferring ownership of the channel as usual, just pass the (string) name of the handler proc "foo". Then make it the script writer's entire responsibility to populate the dest thread with the necessary procs and data for [foo write] et al to be meaningful *there*. I know it's a bit late to react, sorry. But it seems to me that all the special-casing of "thread-transferring an RC" (the hidden "thread::send + pseudo-vwait", plus all the stuff to encapsulate parameters and results without using cross-interp objects, plus the specific steps to avoid deadlock, etc...) would vanish to be replaced by explicit script-level stuff that is already covered in the existing implementation of the primitives. What am I missing ? - login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [64518120f4] (rid 92742) by dgp on 2011-09-19 02:15:53:
- icomment:
On the iocmd-leaks branch, I've committed changes to the tests that solve the corruption between them. Since that was my ultimate goal, I no longer care about this bug. I intend to merge the iocmd-leaks branch soon.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [7140a2eaba] (rid 100640) by andreas_kupries on 2011-09-20 00:51:38:
- icomment:
Alexandre, I don't remember if I considered your alternative. Not surprising, given that it is seven years now since the TIP http://tip.tcl.tk/219.html was made. On re-reading the section regarding the handling of the interaction between RCs and Threads I might have have considered it and discarded, given that I provide a use case for the current design (Using a pair of RCs for stream-based thread communication). Not sure however. > When transferring a RC, in addition to tranferring ownership of the > channel as usual, just pass the (string) name of the handler proc "foo". > Then make it the script writer's entire responsibility to populate the dest > thread with the necessary procs and data for [foo write] et al to be > meaningful *there*. Note that this makes RCs (a) special (case) with regard to transfering between threads. With all other channel types you can simply transfer and them use them. With RCs you now have to perform lots of setup to make it work. In this my approach fits IMVHO better, without special case setup on part of the script writer. The user does not have to care if it is an RC which is transfered, or not. This becomes especially important when your script is an application using channel provided by some library. You usually don't want to know how the channel is implemented, and for this you would have to. > I know it's a bit late to react, sorry. But it seems to me that all the > special-casing of "thread-transferring an RC" (the hidden "thread::send + > pseudo-vwait", plus all the stuff to encapsulate parameters and results > without using cross-interp objects, plus the specific steps to avoid > deadlock, etc...) would vanish to be replaced IOW. the complexity and special casing is not really going away, only simply shifted around and changing its nature a bit (setup with yours vs. all the internal transfer mgmt with mine). > by explicit script-level > stuff that is already covered in the existing implementation of the > primitives.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [1e2e740be2] (rid 90935) by dgp on 2011-09-20 01:20:31:
- assignee changed to: "dgp"
- closedate changed to: "2011-09-19T18:20:31"
- closer changed to: "dgp"
- icomment:
allow_comments - 1 Robust versions of this test and its neghbors are now merged to trunk from iocmd-leaks branch. These tests now avoid issues where tests can fail due to events from one test corrupting the expected value in another test. There are still some issues with these tests that they can sometimes segfault when in an environment where full thread finalization is being tested. These remaining matters are now the subject of 3411310. The "total re-design" ideas arising now may well be the true answer, but might be better pursued in an RFE Ticket / dev branch of its own.
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "dgp"
Ticket change [7e33a009c5] (rid 97365) by ferrieux on 2011-09-20 02:10:48:
- assignee changed to: "andreas_kupries"
- icomment:
allow_comments - 0 Andreas, thanks for addressing my points. I don't want to appear as fighting your ideas. It's simply that you are much more courageous than I am :D. Let me just answer a few of your arguments from the lazy man's standpoint: > [use case for interthread comm] Still doable with plain, documented [thread::send] instead of its hidden ersatz inside IORchan, right ? > [orthogonality, channel type agnosticism] Okay but "<@" already exposes the special nature of refchans (and channel transforms, for that matter). Also, while some cases of channel transfer come to mind (like the client socket in a network server), I really can't imagine a modular app ignoring the kind of channel that it's transferring ... and yet accepting the two peculiar consequences of transferring an RC: (a) that the mother thread stays in evloop, and (b) that each and every channel method incurs a round trip to this mother thread. Hardly transparent, I'd say :} > IOW. the complexity and special casing is not really going away, only > simply shifted around and changing its nature a bit (setup with yours vs. > all the internal transfer mgmt with mine). Yes. The key word here is "changing its nature": the burden of setup is entirely in script land ! This means that any complex interactions are emergent properties of the existing primitives, which are covered in dozens of atomic tests, hence much easier to debug : thread::send, vwait, chan create, etc. Moreover, this burden seems much lighter to me. Indeed, instead of emulating the interthread forwarding of refchan methods, one is more likely to just implement them in the other thread, on top of whatever true channel was transferred beforehand. Not much complexity indeed. But I guess it's way too late anyway. Let's hope few deadlocks and race conditions still exist in there ;-)
- login: "ferrieux"
- mimetype: "text/plain"
- resolution changed to: "None"
- status changed to: "Open"
- username: "ferrieux"
Ticket change [51162e918d] (rid 126080) by ferrieux on 2011-09-20 02:18:54:
- assignee changed to: "dgp"
- closedate changed to: "2011-09-19T19:18:54"
- closer changed to: "ferrieux"
- resolution changed to: "Fixed"
- status changed to: "Closed"