Error when aborting in-progress download #4

Open
burzmali opened this Issue Oct 2, 2010 · 1 comment

Projects

None yet

2 participants

@burzmali

Hello,
When calling abort! on an in-progress download(er), pending operations will crash the SFTP library.
example crash:

/usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/download.rb:337:in `on_read': read /somefile.txt: invalid handle (9) (RuntimeError)
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/request.rb:87:in `call'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/request.rb:87:in `respond_to'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:948:in `dispatch_request'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:911:in `when_channel_polled'
        from /usr/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/channel.rb:311:in `call'
        from /usr/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/channel.rb:311:in `process'
        from /usr/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:214:in `block in preprocess'
        from /usr/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:214:in `each'
        from /usr/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:214:in `preprocess'
        from /usr/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:197:in `process'
        from /usr/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:161:in `block in loop'
        from /usr/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:161:in `loop'
        from /usr/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh/connection/session.rb:161:in `loop'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:802:in `loop'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/request.rb:72:in `wait'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:842:in `wait_for'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:191:in `open!'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/file_factory.rb:40:in `open'
        from ./FTP_Mirror.rb:95:in `copy'
        from ./FTP_Mirror.rb:72:in `block in recurse'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `block in foreach'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `each'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `foreach'
        from ./FTP_Mirror.rb:59:in `recurse'
        from ./FTP_Mirror.rb:67:in `block in recurse'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `block in foreach'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `each'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `foreach'
        from ./FTP_Mirror.rb:59:in `recurse'
        from ./FTP_Mirror.rb:67:in `block in recurse'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `block in foreach'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `each'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `foreach'
        from ./FTP_Mirror.rb:59:in `recurse'
        from ./FTP_Mirror.rb:67:in `block in recurse'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `block in foreach'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `each'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `foreach'
        from ./FTP_Mirror.rb:59:in `recurse'
        from ./FTP_Mirror.rb:67:in `block in recurse'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `block in foreach'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `each'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `foreach'
        from ./FTP_Mirror.rb:59:in `recurse'
        from ./FTP_Mirror.rb:67:in `block in recurse'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `block in foreach'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `each'
        from /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/dir.rb:33:in `foreach'
        from ./FTP_Mirror.rb:59:in `recurse'
        from ./FTP_Mirror.rb:268:in `block (2 levels) in '
        from ./FTP_Mirror.rb:267:in `each'
        from ./FTP_Mirror.rb:267:in `block in '
        from ./FTP_Mirror.rb:263:in `each'
        from ./FTP_Mirror.rb:263:in `'

This was provoked thusly:

dl =@session.sftp.download(src,dst) do |bla|
some block
end
...
dl.abort!
...

This small change seems to fix it:

-- /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/download.rb.orig       2010-10-01 15:59:15.237631526 -0700
+++ /usr/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/download.rb    2010-10-01 18:20:19.946939769 -0700
@@ -325,6 +325,7 @@
       # and returned data, this will call #download_next_chunk to read the
       # next bit from the file. Otherwise the file will be closed.
       def on_read(response)
+        return unless active?
         entry = response.request[:entry]
 
         if response.eof?

on_read is called but the response.request for the aborted transfer has already been cleared by the call to abort! (I think)

@delano
Collaborator

Thanks for the report! I'll take a look at the problem this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment