Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2014-12-18
18:07 • Closed ticket [7c187a3773]: Abort: Reuse of ChannelBuffer! when using sockets w... artifact: 6803939fe3 user: dgp
18:06
[7c187a3773] Fix error in managing inStatePtr->inQueueTail value in the byte-moving optimized path o... check-in: fca565edf9 user: dgp tags: trunk
17:36 • Ticket [7c187a3773] Abort: Reuse of ChannelBuffer! when using sockets with fcop... artifact: 54569b1df1 user: dgp
16:22 • Ticket [7c187a3773]: 3 changes artifact: 019bfc92e3 user: dgp
2014-12-16
12:11 • New ticket [7c187a3773]. artifact: 4f385cbc20 user: blange

Abort: Reuse of ChannelBuffer! when using sockets with fcopy or tls/ssl on Linux

Closed / Fixed7c187a377311556abe067987cbd6a4009becf689Created 12 years agoUpdated 12 years ago
Descriptionplain2014-12-16 12:11:55
While trying to switch our apps to 8.6, we get crashes using sockets with 
fcopy or TSL/SSL.
The code used is running unmodified since 8.4, but (sometimes/often) 
aborts on 8.6.
It is not easy to reproduce - it only happens if client and server are on 
separate hosts and then only in 1 out of 5/10/400 times, as it seems to 
depend on network latency/buffering ..
If the fcopy in the client example is replaced by an the read everything 
works as expected.
But we are also seeing the same abort when doing https requests ...

The loop in the client should not the problem, as we also tested this 
with the loop in a surrounding shell script.

Normally the server part is a C-program, but we did one in tcl for the 
demonstration which serves the same purpose.
We use an executable currently built from ActiveTcl 8.6.3.1.298624 which 
runs the client-script below.

Current platforms used are SLES11-SP3 and openSuse 13.1.
We also tried to reproduce the error with a windows client, but the error does not occur. (I presume due to the different I/O subsystems)
 
If you need any more info .... please call  :-)

Benno

----------server part -------------------------------------
puts stderr "TCL $::tcl_patchLevel"
#
#   bug server
#
set hport 6666

set ::dumlen 65532
set ::dumdat [string repeat {*} $::dumlen]

proc gen_ans { ch }\
{
    # answer it
    set nfiles 3
    puts $ch "$nfiles|xxxxxxxxxx"

    for { set nf 0 } { $nf < $nfiles } { incr nf }\
    {
        fconfigure ${ch} -translation crlf -buffering line

        # send header info
        set lhdr [list [string length $::dumdat] "testadadadada.dat" S {}]
        puts $ch [join $lhdr {|}]

        fconfigure ${ch} -translation binary -buffering none
        puts -nonewline $ch $::dumdat
    }
}

proc do_bugserv { ch adr port } \
{
    fconfigure $ch -blocking true
    fconfigure $ch -buffering line

    # read initial request
    set rq [gets $ch]

    # answer it
    gen_ans $ch

    close $ch
}

set sck [socket -server do_bugserv $hport]

vwait ::done

----------client part -------------------------------------
puts stderr "TCL $::tcl_patchLevel"

set svr   <<server-host>>
set hport 6666

for {set n 0} { 1 } {incr n} \
{
    puts stderr "RUN #$n"

    set sock [socket ${svr} ${hport}]

    if { "$sock" == "" } \
    {
        puts stderr "conn failed !!"
        exit -1
    }
    fconfigure ${sock} -translation auto -buffering line

    # send intial request
    puts ${sock} "xxxxxxx|yy"

    # get initial response from server
    set resp [gets ${sock}]
    # 1. - # of files
    # 2. - unused
    puts stderr "resp=<[string length ${resp}]><${resp}>"

    lassign [split ${resp} {|}] nfiles dum

    if { ${nfiles} > 0 } \
    {
        for { set fi 0 } { ${fi} < ${nfiles} } { incr fi } \
        {
            # get file-response from server
            set resp [gets ${sock}]

            lassign [split ${resp} {|}] fsize fname - -

            puts stderr "receiving <$fname> - <$fsize>"

            if { ${fsize} > 0 } \
            {
                fconfigure ${sock} -translation binary -buffering none

                set tfile {tmp.rcv}

                set ef [open ${tfile} {w+}]
                fconfigure ${ef} -translation binary

                set rc [fcopy ${sock} ${ef} -size ${fsize}]
                #-OK-- set rc [read ${sock} ${fsize}]

                close ${ef}

                fconfigure ${sock} -translation auto -buffering line
            } \
            else \
            {
                puts stderr "size error on <${fname}> !!"
                exit -1
            }
        }
    } \
    else \
    {
        puts stderr "load info error !!"
        exit 1
    }
    close ${sock}
}
puts stderr "DONE ok."
exit 0
Referenced by1
  • fca565edf9[7c187a3773] Fix error in managing inStatePtr->inQueueTail value in the byte-moving optimized path of [chan copy]. Thanks to Benno. check-in2014-12-18 18:06:51
dgpplain2014-12-18 16:22:40
Good test scripts!  Reproduced on current trunk.
dgpplain2014-12-18 17:36:16

This is the fix.  Will commit once I've added a test case.

Index: generic/tclIO.c
==================================================================
--- generic/tclIO.c
+++ generic/tclIO.c
@@ -9213,10 +9213,13 @@
     } else {
        outStatePtr->outQueueHead = inStatePtr->inQueueHead;
     }
     outStatePtr->outQueueTail = tail;
     inStatePtr->inQueueHead = bufPtr;
+    if (inStatePtr->inQueueTail == tail) {
+       inStatePtr->inQueueTail = bufPtr;
+    }
     if (bufPtr == NULL) {
        inStatePtr->inQueueTail = NULL;
     }
 
     code = FlushChannel(csPtr->interp, outStatePtr->topChanPtr, 0);
dgpplain2014-12-18 18:07:25
Test and fix committed for 8.6.4.
Log in (anonymous is fine) to add a comment.