Menu

#1145 ftp client close hangs

open
ftp (55)
5
2009-06-26
2009-06-26
No

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.

Discussion

  • Shaun Zinck

    Shaun Zinck - 2011-04-18

    The first issue you describe was fixed in version 1.38 on Tue Feb 15 00:06:33 2005 UTC.

     
  • Shaun Zinck

    Shaun Zinck - 2011-04-18

    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.

     
  • Andreas Kupries

    Andreas Kupries - 2011-04-18

    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.