Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2011-08-19
22:25 • Ticket [2981154fff] async.test segfault status still Closed with 4 other cha... artifact: 6d78635a7e user: ferrieux
21:35 • Ticket [2981154fff]: 4 changes artifact: 3784d0241d user: dgp
21:04 • Closed ticket [2981154fff]. artifact: e797b0a458 user: ferrieux
13:59 • Ticket [2981154fff]: 4 changes artifact: ea5a020825 user: ferrieux
13:56 • Ticket [2981154fff]: 4 changes artifact: 4b60dc48b8 user: ferrieux
05:59 • Ticket [2981154fff]: 4 changes artifact: bb2ec2a979 user: ferrieux
05:51 • Ticket [2981154fff]: 4 changes artifact: 763be709d3 user: ferrieux
05:14 • Ticket [2981154fff]: 4 changes artifact: 03e70ef982 user: ferrieux
04:44 • Ticket [2981154fff]: 4 changes artifact: 60313d4ccc user: ferrieux
2011-04-14
22:39 • Ticket [2981154fff]: 4 changes artifact: ef702920a4 user: dgp
2010-04-02
15:11 • New ticket [2981154fff]. artifact: ae9057143b user: dgp

async.test segfault

Closed / Fixed2981154fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 15 years ago
Descriptionplain2010-04-02 15:11:17
Using the 8.5.8 sources (so I rule out more recent commits)
and with a --enable-threads --enable-symbols build, I
sometimes see a segfault at the end of async.test.

I managed to catch it in gdb:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x40646b90 (LWP 825)]
0x0814bcfb in Tcl_MutexLock (mutexPtr=0x10)
    at /home/dgp/cvs/tcl8.5/unix/../unix/tclUnixThrd.c:519
519         if (*mutexPtr == NULL) {


(gdb) bt
#0  0x0814bcfb in Tcl_MutexLock (mutexPtr=0x10)
    at /home/dgp/cvs/tcl8.5/unix/../unix/tclUnixThrd.c:519
#1  0x08067c88 in Tcl_AsyncMark (async=0x8e0b274)
    at /home/dgp/cvs/tcl8.5/unix/../generic/tclAsync.c:167
#2  0x08054baf in AsyncThreadProc (clientData=0x8e16c18)
    at /home/dgp/cvs/tcl8.5/unix/../generic/tclTest.c:936
#3  0x080c1fbd in NewThreadProc (clientData=0xbbe12f0)
    at /home/dgp/cvs/tcl8.5/unix/../generic/tclEvent.c:1487
#4  0x0088773b in start_thread () from /lib/libpthread.so.0
#5  0x007dccfe in clone () from /lib/libc.so.6


Don't know whether this is another symptom of 
Tcl Bug 2869384.

I believe that when the segfault happens, it is
always after test async-4.3 has failed
(Tcl Bug 1774689).  However, async-4.3
can also fail without a segfault following.
dgpplain2011-04-14 22:39:52
FWIW, I just saw this one again on trunk tip.
ferrieuxplain2011-08-19 04:44:01
Quoting mistachkin in 1774689:

   To see this test fail reliably, simply change the line in proc hang3
   from: [string repeat {;incr i;} 1500000] to: [string repeat {;incr i;}
   150]

doing this I get it reliably on trunk tip.
ferrieuxplain2011-08-19 05:14:34
I also get non-systematic segfault, but there're news: the non-segfaulting is correlated to Tcl_AsyncMark *not* being called. It's an iff. So there's a race condition that hides the segfault by not letting the thread go far enough.
ferrieuxplain2011-08-19 05:51:33
Probability of segfault gets close to 1 with 15 instead of 150 in the modified loop.
Theory: the asyncmark may happen:
  (a) during the loopless stretch of BC 
  (b) during the main interp's teardown
  (c) not at all, since the process has exited
Clearly only the gray area (b) segfaults. I guess during teardown things are not as airtight as during normal operation.
ferrieuxplain2011-08-19 05:59:27
Come to think of it, as mistachkin noted, the whole test setup is geared towards (a), ie there's absolutely no effort to be teardown-proof. So playing with too small stretches of BC is completely out of the intended range.
Hence, I believe the proper fix is to increase the size of the loopless BC stretch in that test.
ferrieuxplain2011-08-19 13:56:14
To clarify: in the comments below, "teardown" is the test's cleanup part which does Tcl_AsyncDelete.
So maybe there's a race condition between Tcl_AsyncDelete and the real invocation of an already Tcl_AsyncMark'ed handler. In case this is true, it ought to be fixed generically rather than pulled under the rug.
ferrieuxplain2011-08-19 13:59:59
OK, the previous hypothesis is proven wrong: the bug is really tclTest.c's lack of protection of its interthread data access. Will add a mutex.
ferrieuxplain2011-08-19 21:04:34
Fixed in HEAD, by (1) mutex-protecting the process-wide static holding the list of TestAsyncHandlers (along with the unique id counter ;-), and (2) moving from a pointer-to-struct to an integer-id API in async handlers. The mutex-protected lookup by id is done twice: once in the alien thread, as a prerequisite to calling AsyncMark with the proper token; and once in the async handler, since the handler may have been deleted between the two.
Passes test suite. Verified that even wit the 1500000->15 tweak, even though the test consistently fails, it never segfaults.
dgpplain2011-08-19 21:35:40
Is the patch suitable for backport
to 8.5.11 ?
ferrieuxplain2011-08-19 22:25:22
Backported.
Log in (anonymous is fine) to add a comment.