Tcl Library Source Code

View Ticket
Login
Ticket UUID: 2813069
Title: ftp client close hangs
Type: Bug Version: None
Submitter: russellbell Created on: 2009-06-26 23:38:55
Subsystem: ftp Assigned To: andreas_kupries
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2014-02-21 21:11:42
Resolution: Fixed Closed By: aku
    Closed on: 2014-02-21 21:11:42
Description:
I've found a bug in the ftp client library 2.4.8 that bites
when a connection is closed.  When you call ::ftp::Close $handle
you sometimes get a TCL exception (thrown in an event handler
so a catch around ::ftp::Close doesn't help) and sometimes
you get an endless loop.  Depends on the ftp server you're
talk to and doesn't happen consistently, but enough to be
annoying.

The faulty code is about line 35 of ::ftp::StateHandler which
does "set number [gets $sock bufline]".  This code reads
a continuation line, so normally isn't called after the
socket is closed, but sometimes it is and an exception is
the result.  The fix is to wrap in a catch.

But then the second bug bites - this code is in a loop and
if the gets returns <= 0, the loop is infinite.  The fix is to
break from the loop, and change the code structure a little
to ensure "if { [eof $ftp(CtrlSock)] } ..." gets called
in this case.

I believe this is a separate issue to 1076923 found by Keith
Vetter - that was the gets on line 16 of ::ftp::StateHandler.

If it's helpful I can provide source for the fix.
User Comments: aku added on 2014-02-21 21:11:42:
This looks to be fixed for quite some time now, with no feedback from the original submitter regarding the veracity of the fix. Closing as fixed.

andreas_kupries added on 2011-04-19 02:30:12:
Shaun's patch has been committed to CVS Head, package version bumped to 2.4.10.

Russel, you might wish to recheck your problem. If it persists I would like to get a patch/sources for the fix, taking Shaun's changes into account.

szinck added on 2011-04-19 01:20:09:
Hi Russell, I had the same issue as you on the second bug you mentioned.  If the connection is closed before the last line of a multi-line reply is sent, the ftp client will hang.  I couldn't attach a file, otherwise I would've just added it to this bug.  I created a new bug #3288977 and attached a patch.

szinck added on 2011-04-19 01:02:45:
The first issue you describe was fixed in version 1.38 on Tue Feb 15 00:06:33 2005 UTC.