Tcl Source Code

View Ticket
Login
Ticket UUID: 1829708
Title: http.test triggers segfault (sometimes)
Type: Bug Created on: 2007-11-10 23:56:38
Submitter: msofer Assigned to: vasiljevic
Subsystem: 49. Threading Severity:
Priority: 8 Last modified: 2011-08-19 23:10:50
Status: Open Closed by:
Resolution: None Closed on:
Version: obsolete: 8.5b3
Description:
http.test triggers a threading segfault; this happens in a somewhat aleatory manner, but after a few rapid repetitions of the test it triggers reliably here.


$ make test TESTFLAGS="-f http.test"
...
++++ http-7.3 PASSED
++++ http-7.4 PASSED
Test file error: child killed: segmentation violation

----
The backtrace is

#0  0x400367f4 in __pthread_mutex_unlock_usercnt () from /lib/tls/i686/cmov/libpthread.so.0
#1  0x40036bf0 in pthread_mutex_unlock () from /lib/tls/i686/cmov/libpthread.so.0
#2  0x08148f24 in Tcl_MutexUnlock (mutexPtr=0x817fa38) at /home/CVS/tcl_SF_clean/unix/../unix/tclUnixThrd.c:522
#3  0x0814a168 in Tcl_WaitForEvent (timePtr=0x0) at /home/CVS/tcl_SF_clean/unix/../unix/tclUnixNotfy.c:871
#4  0x08107cb9 in Tcl_DoOneEvent (flags=-3) at /home/CVS/tcl_SF_clean/unix/../generic/tclNotify.c:957
#5  0x08066876 in Tcl_ThreadObjCmd (dummy=0x0, interp=0x8265458, objc=2, objv=0x826dd28) at /home/CVS/tcl_SF_clean/unix/../generic/tclThreadTest.c:385
#6  0x0806d575 in TclEvalObjvInternal (interp=0x8265458, objc=2, objv=0x826dd28, command=0x8291b62 "testthread wait\n    ", length=16, flags=0)
    at 
/home/CVS/tcl_SF_clean/unix/../generic/tclBasic.c:3661

----

% parray tcl_platform
tcl_platform(byteOrder)   = littleEndian
tcl_platform(machine)     = i686
tcl_platform(os)          = Linux
tcl_platform(osVersion)   = 2.6.20-16-generic
tcl_platform(platform)    = unix
tcl_platform(pointerSize) = 4
tcl_platform(threaded)    = 1
tcl_platform(user)        = mig
tcl_platform(wordSize)    = 4
User Comments:
msofer added on 2007-11-12 22:26:47:
Logged In: YES 
user_id=148712
Originator: YES

That was HEAD as of Nov 10; repro with the released 8.5b2.

msofer added on 2007-11-12 23:10:36:
Logged In: YES 
user_id=148712
Originator: YES

8.5a6 too

msofer added on 2007-11-13 07:36:56:
Logged In: YES 
user_id=148712
Originator: YES

Note that this happens *after* the last test; gwlester reporting seeing failures on app exit under osx too.

msofer added on 2007-11-13 22:57:55:
Logged In: YES 
user_id=148712
Originator: YES

Can't seem to trigger this anymore after [Bug 1618235] was fixed earlier today. Related?

vasiljevic added on 2007-11-13 23:06:02:
Logged In: YES 
user_id=95086
Originator: NO

most probably. thx to dkf for backporting the 
compat code from 8.4 branch.
I'm just too low on time this week.

msofer added on 2007-11-28 17:26:42:
Logged In: YES 
user_id=148712
Originator: YES

Still there in head as of today

dgp added on 2007-12-04 03:49:44:
Logged In: YES 
user_id=80530
Originator: NO


Should this bug block 8.5.0?

vasiljevic added on 2007-12-04 04:03:39:
Logged In: YES 
user_id=95086
Originator: NO

I do not know. I'm unable to reproduce this on any machine
that I have access to. I would not consider this a show stopper
if you ask me.

georgeps added on 2007-12-15 02:38:51:
Logged In: YES 
user_id=585068
Originator: NO

I can't attach files to this bug report for some reason, so here are some links:

This is an abort/panic related to the problem:
http://paste.tclers.tk/633

This is a log and the modified test file that it took to bring out the problem in an --enable-symbols=all build.  It's easier without --enable-symbols.  

http://paste.tclers.tk/632

This has to be causing a problem for someone.  I think this should block 8.5, unless threads aren't important (which they certainly aren't to me).

-GPS

georgeps added on 2007-12-15 03:12:35:
Logged In: YES 
user_id=585068
Originator: NO

I found a new buggy path by just changing the script a bit.

I made a small change to the script.  I removed the after 1000; before the testthread wait

if {[catch {package require http 2} version]} {
    if {[info exists http2]} {
catch {puts "Cannot load http 2.* package"}
return
    } else {
catch {puts "Running http 2.* tests in slave interp"}
set interp [interp create http2]
$interp eval [list set http2 "running"]
$interp eval [list set argv $argv]
$interp eval [list source [info script]]
interp delete $interp
return
    }
}
set httpthread [testthread create "
    socket -server {apply {{chan addr port} { testthread wait}} 6666};
    testthread wait"]

testthread send -async $httpthread {
  testthread exit
}

Backtraces available here:
http://paste.tclers.tk/634

vasiljevic added on 2007-12-15 03:35:38:
Logged In: YES 
user_id=95086
Originator: NO

OK, all relax a bit...

The reason why I said this isn't the show-stopper is because I strongly
believe (and George's last change proves that) that we are hitting a well
known bug in Tcl teardown where the master thread exits before some
other thread created after the startup. In this case the master exiting 
thread releases some resources still used by the existing thread(s) so
some of them may (do) freak out. 
W/O rewriting the whole Tcl finalization mechanism (and introducing 
refcounts on shared resources) you can't solve that problem. But you
can very easily avoid it by properly tearing down all threads before
the master one (first one in the process, or better, first one that
loaded the Tcl lib) exits. 

So I believe there is no reason to halt the 8.5.0 because if that, as this
one is sitting in the core since the introduction of threads in Tcl.

I will have to see some long-running thread-test that uses the Tcl threading
extension which will core the process. This one I will pay immediate attention
to, as we are absolutely and totally dependent on the thread-related stability
of the core.

georgeps added on 2007-12-15 04:06:17:
Logged In: YES 
user_id=585068
Originator: NO

"A well known bug" OK.  I shall have to quote you on that.  I'm going to suggest that we note this "well known bug in the README/Hall of Shame, because it wasn't known to me, and apparently others.

vasiljevic added on 2007-12-15 04:19:25:
Logged In: YES 
user_id=95086
Originator: NO

Sorry, I thought this is a well-known behaviour...
If you are interested, you can begin at the bug
#597575 and then move on...

hobbs added on 2007-12-15 04:35:22:
Logged In: YES 
user_id=72656
Originator: NO

It was well known to me, and is no surprise for pthreads-based systems.  Note that this isn't even a public API we are talking about - it uses testthread.  The issue with public threads needing to have proper shutdown should get noted when it isn't a special test API.  It should go into the Thread module docs asap though.

ferrieux added on 2011-08-19 23:10:50:
Status ?