Tcl Library Source Code

View Ticket
Login
2014-02-21
21:09 • Closed ticket [eb0b15d598]: Ftp module throws errors into the event loop plus 6 other changes artifact: fb6f194908 user: aku
21:05
ftp - Merged fix for ticket [eb0b15d598]. Bumped ftp to version 2.4.13. check-in: 863ac2e0d8 user: andreask tags: trunk
2014-02-17
17:13 • Add attachment ftp.patch to ticket [eb0b15d598] artifact: 1a7612e1ad user: anonymous
2014-01-29
21:26 • Ticket [eb0b15d598] Ftp module throws errors into the event loop status still Open with 4 other changes artifact: 61427bd3a1 user: anonymous
21:11
Ticket [eb0b15d598] - ftp - Extended debug narrative for the state machine operation to help investigation of the problem check-in: 0adb77c50b user: andreask tags: ftp-bug-eb0b15d598
2014-01-27
18:54 • Ticket [eb0b15d598] Ftp module throws errors into the event loop status still Open with 4 other changes artifact: 74bce435e8 user: aku
2014-01-24
20:40 • New ticket [eb0b15d598]. artifact: c316eac4ca user: anonymous

Ticket UUID: eb0b15d5981300c3c13b90ab4d3e7cd18c36095a
Title: Ftp module throws errors into the event loop
Type: Bug Version: ftp 2.4.11
Submitter: anonymous Created on: 2014-01-24 20:40:37
Subsystem: ftp Assigned To:
Priority: 5 Medium Severity: Critical
Status: Closed Last Modified: 2014-02-21 21:09:38
Resolution: Fixed Closed By: aku
    Closed on: 2014-02-21 21:09:38
Description:
The module regularly throws errors into the event loop, which are very hard to recover from.  I have verified that the problem is reproducable on my desktop machine (Win7 using mingw) and an embedded Linux device.

I have a test script which shows the problem.  In the following output, there is one successful NList command, and the second NList causes the error.

===
[2014-01-24T14:26:34] [info] [stress] Count 19/100 NList = /Outbox/Store_11420/Done /Outbox/Store_11420/PCO-11420-140123-183131.xml
[2014-01-24T14:26:34] [debug] [DisplayMsg] ftp: info | -> rc="   "
[2014-01-24T14:26:34] [debug] [DisplayMsg] -> msgtext=""
[2014-01-24T14:26:34] [debug] [DisplayMsg] -> state="type"
[2014-01-24T14:26:34] [debug] [DisplayMsg] ftp: info | ---> TYPE A
[2014-01-24T14:26:34] [debug] [DisplayMsg] ftp: info | -> rc="200"
[2014-01-24T14:26:34] [debug] [DisplayMsg] -> msgtext="200 Type set to A."
[2014-01-24T14:26:34] [debug] [DisplayMsg] -> state="type_sent"
[2014-01-24T14:26:34] [debug] [DisplayMsg] ftp: control | C: 200 Type set to A.
[2014-01-24T14:26:34] [debug] [DisplayMsg] ftp: info | -> rc="   "
[2014-01-24T14:26:34] [debug] [DisplayMsg] -> msgtext=""
[2014-01-24T14:26:34] [debug] [DisplayMsg] -> state="nlist_active"
[2014-01-24T14:26:34] [debug] [DisplayMsg] ftp: data | D: Port is 59758
[2014-01-24T14:26:34] [debug] [DisplayMsg] ftp: info | ---> PORT 192,168,16,140,233,110
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="200"
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext="200 PORT command successful."
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="nlist_open"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | ---> NLST /Outbox/Store_11420
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: control | C: 200 PORT command successful.
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="150"
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext="150 Opening ASCII mode data connection."
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="list_sent"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: control | C: 150 Opening ASCII mode data connection.
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: data | D: Connection from <ip addr>:20
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="226"
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext="226 Transfer complete."
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="list_close"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: data | D: Port closed
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: control | C: 226 Transfer complete.
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="   "
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext=""
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="type"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | ---> TYPE I
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="200"
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext="200 Type set to I."
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="type_sent"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: control | C: 200 Type set to I.
[2014-01-24T14:26:35] [info] [stress] Count 20/100 NList = /Outbox/Store_11420/Done /Outbox/Store_11420/PCO-11420-140123-183131.xml
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="   "
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext=""
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="type"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | ---> TYPE A
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="200"
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext="200 Type set to A."
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="type_sent"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: control | C: 200 Type set to A.
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="   "
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext=""
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="nlist_active"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: data | D: Port is 59759
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | ---> PORT 192,168,16,140,233,111
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="200"
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext="200 PORT command successful."
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="nlist_open"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | ---> NLST /Outbox/Store_11420
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: control | C: 200 PORT command successful.
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="150"
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext="150 Opening ASCII mode data connection."
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="list_sent"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: control | C: 150 Opening ASCII mode data connection.
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="226"
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext="226 Transfer complete."
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="list_close"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: control | C: 226 Transfer complete.
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | -> rc="   "
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> msgtext=""
[2014-01-24T14:26:35] [debug] [DisplayMsg] -> state="type"
[2014-01-24T14:26:35] [debug] [DisplayMsg] ftp: info | ---> TYPE I
[2014-01-24T14:26:35] [error] [bgerror] bgerror: Unknown state "type_sent"
[2014-01-24T14:26:35] [error] [bgerror] Unknown state "type_sent"
[2014-01-24T14:26:35] [error] [bgerror]     while executing
[2014-01-24T14:26:35] [error] [bgerror] "error "Unknown state \"$ftp(State)\"""
[2014-01-24T14:26:35] [error] [bgerror]     (procedure "::ftp::InitDataConn" line 55)
[2014-01-24T14:26:35] [error] [bgerror]     invoked from within
[2014-01-24T14:26:35] [error] [bgerror] "::ftp::InitDataConn 0 sock560 <ip addr> 20"
[2014-01-24T14:26:36] [debug] [DisplayMsg] ftp: info | -> rc="200"
[2014-01-24T14:26:36] [debug] [DisplayMsg] -> msgtext="200 Type set to I."
[2014-01-24T14:26:36] [debug] [DisplayMsg] -> state="type_sent"
===

Here is the script:
======
package require log
package require ftp

namespace import ::log::log*
namespace import ::ftp::*

# Set log package options
::log::lvSuppressLE warning 0
::log::lvSuppress debug 0
::log::lvCmdForall logCmd

proc logCmd {lvl txt} {
    if {[info level] > 2} {
        set method [lindex [info level -2] 0]
    } else {
        set method "global"
    }
    set line "\[[clock format [clock seconds] -format {%Y-%m-%dT%H:%M:%S}]\] \[$lvl\] \[$method\] $txt"
    puts stdout $line
    flush stdout
}

# Set ftp package options
namespace eval ftp {
    set VERBOSE 1
    set DEBUG 1

    # Override default output routine
    proc DisplayMsg {s msg {state "info"}} {
        ::log::log debug "ftp: $state | $msg"
        # if {$state eq "error" && [info exists ::errorInfo]} {
        #     ::log::log debug $::errorInfo
        # }
        return
    }
}

proc bgerror {msg} {
    log error "bgerror: $msg"
    if {[info exists ::errorInfo]} {
        log error "$::errorInfo"
    } else {
        log error "errorInfo does not exist"
    }
}

proc connect {addr} {
    log info "Opening anonymous FTP connection to $addr"
    set ftp [::ftp::Open $addr anonymous anonymous -port 21 -timeout 20]
}

proc disconnect {ftp} {
    ::ftp::Close $ftp
}

proc stress {ftp count} {
    for {set n 0} {$n < $count} {incr n} {
        set nlist [::ftp::NList $ftp /Outbox/Store_11420]
        log info "Count $n/$count NList = $nlist"
    }
}
======
User Comments: aku added on 2014-02-21 21:09:38:
Most of the interaction directly by mail.

Generally this was a race condition.
The main sequencer for the control connection (MSCC) stepped independently of the code handling the data connection (DC).

In this case the server opened the DC very late, at a time where the MSCC had stepped already beyond the last state of the sequence dealing with the data command (here NLST, state 'list_close'). InitDataConn thus encountered a main state it had no idea what to do with.

Solution was an additional marker field in the state array of the connection, managed by OpenActiveConn, InitDataConn, and a new procedure WaitDataConn to have the MSCC wait in the last state of any sequence (*_close) for the arrival of the DC before stepping further.

The new procedure is added to all these states.

Work on branch "ftp-bug-eb0b15d598"
Final fix in revision [6474b535bb] of the branch.
Trunk merge done with revision [863ac2e0d8].
Package bumped to version 2.4.13.
Committed.
Pushed.

Whew.

anonymous (claiming to be dgood`) added on 2014-01-29 21:26:02:
I'm testing against two instances of MS FTP server, one on a physical server, and on on Amazon EC2.  The trace was using an Active FTP connection, port 21.  Passive connections blow up as well, but I have tested this far less, so I don't want to say too much about it right now.

aku added on 2014-01-27 18:54:03:
Does this issue happen with a specific ftp server, or will any server do ?

Attachments: