[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Does Ruby's FTP lib have a ghostly bug?

S. Robert James

1/23/2007 7:50:00 PM

Sometimes when using Ruby's FTP lib, I get this weird error:
#<EOFError: end of file reached>

I get this both on Linux and Windows. Googling around shows that other
people have reported it, although no one seems to know what causes it
or how to solve it (other than trying to reboot).

http://jonaquino.blogspot.com/2005/03/ruby-ftp-...
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...

Looking at the source, my only guess is that it's caused if the client
tries to read before the remote host has sent the data. (But I don't
know enough about Ruby socket programming for this to be more than a
guess.)

# net/ftp.rb:210
def getline
line = @sock.readline # if get EOF, raise EOFError
line.sub!(/(\r\n|\n|\r)\z/n, "")

Anyone capable of solving this bug, or at least have a workaround?




(Here is a stack trace:
#<EOFError: end of file reached>
"/ruby/lib/ruby/1.8/net/ftp.rb:211:in `readline'"
"/ruby/lib/ruby/1.8/net/ftp.rb:211:in `getline'"
"/ruby/lib/ruby/1.8/net/ftp.rb:221:in `getmultiline'"
"/ruby/lib/ruby/1.8/net/ftp.rb:235:in `getresp'"
"/ruby/lib/ruby/1.8/net/ftp.rb:251:in `voidresp'"
"/ruby/lib/ruby/1.8/net/ftp.rb:176:in `connect'"
"/ruby/lib/ruby/1.8/monitor.rb:229:in `synchronize'"
"/ruby/lib/ruby/1.8/net/ftp.rb:174:in `connect'"
"/ruby/lib/ruby/1.8/net/ftp.rb:136:in `initialize'"
"/ruby/lib/ruby/1.8/net/ftp.rb:120:in `open'"
"my_code/connection.rb:27:in `ftp'" # Net::FTP.open(ftp_host,
username, password)

16 Answers

Ara.T.Howard

1/23/2007 8:08:00 PM

0

S. Robert James

1/23/2007 8:18:00 PM

0


ara.t.how...@noaa.gov wrote:
> can you ftp to the host using the command line 'ftp' program of either windows
> or linux?

Yes! Sorry for not stating that. This is a pure ruby issue - ftp in
general works fine in all situations. Also, even with Ruby, this bug
does not happen 100% of the time. (I haven't tested enough to know
what determines it, but I do know that even for the same (host, user,
pw) it will sometimes work and sometimes not.)

I should add that the app in question makes a large number of ftp
connections to the host, one after the other. (I don't think it caches
them.) Perhaps that is somehow related...

Ara.T.Howard

1/23/2007 9:05:00 PM

0

Ara.T.Howard

1/23/2007 9:07:00 PM

0

S. Robert James

1/23/2007 9:17:00 PM

0

I just added FTP conneciton caching, which seems to have removed the
problem. Therefore, I'll assume that this was *not* a ftp.rb problem,
but rather connections being refused when too many came in. (This
didn't show up on simple command line testing, because the rate was
much slower.) I'll add that being that the EOFError message is quite
cryptic, perhaps whoever maintains ftp.rb could make a more
comprehnsible error message (along with the actual OS level socket
error).

I also need to thank Ara. By asking me what I thought was an obvious
question (does command line ftp work), he forced me to communicate my
assumption ("command line works, cryptic error message --> ergo ftp.rb
problem") and consequently rethink it. Is the command line doing the
same thing as the app? No, it's making a lot fewer connections.

This has served to me as a good lesson in debugging:
1. Can you prove the problem is where you think it is? Expand the
scope.
2. With any bug, there's something that you're wrong about. Perhaps
those things which give you the information you are sure of are
themselves wrong. That is, don't just look for problems where you see
them -- look for problems in all of your proofs to get there.
3. Last, always tell the problem to someone else. Having to
communicate to someone forces you to rethink it. And if that someone
else wants proof (like most good Rubyists), it forces you to prove it.
In this case, when I glanced at the src code, I thought it _did_ cache
the connections. But I was going to paste that line in to the list and
saw that, in this scenario, it wasn't caching them.

Thanks Ara! And thanks comp.lang.ruby!

S. Robert James

1/23/2007 9:18:00 PM

0


S. Robert James wrote:
> perhaps whoever maintains ftp.rb could make a more
> comprehnsible error message (along with the actual OS level socket
> error).

PS - Who do I speak to about this?

Ara.T.Howard

1/23/2007 10:11:00 PM

0

Eric Hodel

1/24/2007 12:15:00 AM

0

On Jan 23, 2007, at 13:20, S. Robert James wrote:
> S. Robert James wrote:
>> perhaps whoever maintains ftp.rb could make a more
>> comprehnsible error message (along with the actual OS level socket
>> error).
>
> PS - Who do I speak to about this?

I'm pretty sure its exactly an EOFError. (You have run out of data
to read.)

$ ruby -rstringio
s = StringIO.new "foo\nbar"
s.readline
s.readline
s.readline
-:4:in `readline': end of file reached (EOFError)
from -:4

Why you've run out of data is more difficult to determine. "out of
data waiting for 'X' may be more helpful, but I'm not sure how easy
that is to determine though.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


S. Robert James

1/24/2007 12:39:00 AM

0

It's being called from an attempt to connect to an FTP site. So, it's
not really an out of data per se, but a failure to connect.

Of course, the implementation may result in that failure causing no
data to be available - but it would be a lot clearer if it would a) let
me know that it didn't connect and b) forward on the OS socket level
error.

Or am I missing something? If the connection did work, but the host
just didn't send any data (ie, broken FTP implementation), it's weird
that several people are reporting it - and that it doesn't seem to
occur outside of ftp.rb. (ie with other languages).

On Jan 23, 7:14 pm, Eric Hodel <drbr...@segment7.net> wrote:
> On Jan 23, 2007, at 13:20, S. Robert James wrote:
>
> > S. Robert James wrote:
> >> perhaps whoever maintains ftp.rb could make a more
> >> comprehnsible error message (along with the actual OS level socket
> >> error).
>
> > PS - Who do I speak to about this?I'm pretty sure its exactly an EOFError. (You have run out of data
> to read.)
>
> $ ruby -rstringio
> s = StringIO.new "foo\nbar"
> s.readline
> s.readline
> s.readline
> -:4:in `readline': end of file reached (EOFError)
> from -:4
>
> Why you've run out of data is more difficult to determine. "out of
> data waiting for 'X' may be more helpful, but I'm not sure how easy
> that is to determine though.
>
> --
> Eric Hodel - drbr...@segment7.net -http://blog.se...
>
> I LIT YOUR GEM ON FIRE!

Jamey Cribbs

1/24/2007 1:41:00 AM

0

S. Robert James wrote:
> Sometimes when using Ruby's FTP lib, I get this weird error:
> #<EOFError: end of file reached>
>


I have 50+ ftp scripts that run daily. I only get this error on one of
those scripts, which, like you observed in a later email, moves a bunch
of files every time it runs, one after another. I put a counter in the
script and I found that it consistently bombed out after moving the 60th
file, i.e. I always got this error when it was attempting to move file
number 61.

HTH,

Jamey Cribbs