Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 779909b303514de41f298a461accd096de3c000437b885cc9813268d8ed5ece9
Ticket: 87271f7cd6ab29a076b36e31041a8c940c20d943
TclOO + coroutine + event loop = coredump
User & Date: dkf on 2022-06-28 12:04:40
Changes

  1. comment changed to:
    # behavior observed with Tcl 8.6.11, 8.6.12 on various Linuxes
    #
    # the following program coredumps when looking after the frame information
    #
    
    # at least 2 instances needed for coredump
    set nworkers 2
    set nrounds 1
    
    proc main {} {
        global nworkers
        for {set n 1} {$n <= $nworkers} {incr n} {A create a$n; a$n schedule}
        after 5000 {puts STOPPING;variable forever false}
        variable forever true
        vwait forever
        return 0
    }
    
    oo::class create A {
        method schedule {} {
            set coro ::coro-[string trim [self] :]
            if {[llength [info commands $coro]] == 0} {
                coroutine $coro my Work
            }
        }
        method Work {} {
            after 0 [info coroutine]; yield
            global nrounds
            while {[incr rounds] <= $nrounds} {
                after 1000 [info coroutine]; yield
            }
            my dump-frames
            # with "after 0 [self] dump-frames" there is no coredump
        }
        method dump-frames {} {
            puts "[self] INFO FRAME=[info frame]"
            for {set i 1} {$i < [info frame]} {incr i} {
                puts [format "\t%2d: %s" $i [info frame $i]]
            }
        }
    }
    
    exit [main]
    
    # a backtrace with gdb
    #
    #0  0x00007fd15d493553 in TclInfoFrame () from /usr/lib/libtcl8.6.so
    #1  0x00007fd15d493e04 in InfoFrameCmd () from /usr/lib/libtcl8.6.so
    #2  0x00007fd15d481d37 in TclNRRunCallbacks () from /usr/lib/libtcl8.6.so
    #3  0x00007fd15d563ed0 in AfterProc () from /usr/lib/libtcl8.6.so
    #4  0x00007fd15d5641cd in TimerHandlerEventProc () from /usr/lib/libtcl8.6.so
    #5  0x00007fd15d544417 in Tcl_ServiceEvent () from /usr/lib/libtcl8.6.so
    #6  0x00007fd15d544719 in Tcl_DoOneEvent () from /usr/lib/libtcl8.6.so
    #7  0x00007fd15d5085d6 in Tcl_VwaitObjCmd () from /usr/lib/libtcl8.6.so
    #8  0x00007fd15d481d37 in TclNRRunCallbacks () from /usr/lib/libtcl8.6.so
    #9  0x00007fd15d483eb0 in TclEvalEx () from /usr/lib/libtcl8.6.so
    #10 0x00007fd15d54ac12 in TclSubstTokens () from /usr/lib/libtcl8.6.so
    #11 0x00007fd15d483882 in TclEvalEx () from /usr/lib/libtcl8.6.so
    #12 0x00007fd15d53790f in Tcl_FSEvalFileEx () from /usr/lib/libtcl8.6.so
    #13 0x00007fd15d53ee9f in Tcl_MainEx () from /usr/lib/libtcl8.6.so
    #14 0x00000000004007a4 in main ()
    
    # with a Tcl compiled with --enable-symbol, gdb tells me
    #
    #0  0x00007fe82e55c4a5 in TclInfoFrame (interp=0x1ac85b0, framePtr=0x24193f8) at /home/an/build/tcl8.6.12/generic/tclCmdIL.c:1392
    1392            Tcl_HashEntry *namePtr = procPtr->cmdPtr->hPtr;
    #
    # here, the procPtr->cmdPtr happens to be NULL
    
  2. icomment:
    The immediate crash appears to be caused by a <code>Proc</code> without a reference to a <code>Command</code>. That should only be possible if the command has been deleted.
    <p>
    I think there will be two parts to this fix:
    <ol>
    <li>Making the code not crash by only running that code stanza below there if both <code>procPtr</code> <em>and</em> <code>procPtr-&gt;cmdPtr</code> are valid. (This is needed because it is possible for code to be running while a procedure is being deleted; the information extractable will be of mixed quality, but that's better than a crash.)
    <li>Working out why the <code>procPtr-&gt;cmdPtr</code> is NULL there; it shouldn't be because it is running at a stage when nothing on the stack is actually dead!
    </ol>
    
  3. login: "dkf"
  4. mimetype: "text/html"