2015-11-23 56 views
0

有人可以請解釋爲什麼這個塊讀操作會拋出一個EOFError?我看到它的方式,它會在完全讀取文件時結束該塊。我錯過了什麼?我該如何解決它?非常感謝。爲什麼這個FTP塊讀取操作拋出EOFError?

注意:我應該提到有時它運行良好,在其他情況下它會拋出EOFError。在同一個文件,該文件是在同一位置...

Net::FTP.open(host=ftp.address, user='********', passwd='********') do |ftp| 
     ftp.passive = true 
     files = ftp.nlst('*') 
     s3 = Aws::S3::Resource.new(region: 'us-east-1') 
     files.each do |file| 
     ftp.getbinaryfile(file, file, 65536) # Copies file to /tmp 
     UpdateVfile.loader(@company, file) # Process file from /tmp 
     s3_file = file + Time.zone.now.strftime("-%Y-%m-%dT%H-%M.xls") 
     obj = s3.bucket('mydatafeed').object(s3_file) # Build object in S3 bucket 
     data = '' 
     ftp.getbinaryfile(file, nil, 65536) do |block| <== EOFError thrown here! 
      data << block 
     end 
     obj.put(body: data) # Write it to S3 
     ftp.delete(file) # Delete the file from FTP 
     end 
    end 

堆棧跟蹤:

An EOFError occurred in background at 2015.11.23 : 

    end of file reached 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:1112:in `readline' 

    ------------------------------- 
Backtrace: 
------------------------------- 

    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:1112:in `readline' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:289:in `getline' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:300:in `getmultiline' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:318:in `getresp' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:351:in `block in sendcmd' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:349:in `sendcmd' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:394:in `makepasv' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:406:in `transfercmd' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:490:in `block (2 levels) in retrbinary' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:199:in `with_binary' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:488:in `block in retrbinary' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:487:in `retrbinary' 
    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:620:in `getbinaryfile' 
    /app/lib/tasks/updates_vfile.rake:40:in `block (6 levels) in <top (required)>' 

FTP DEBUG_MODE OUTPUT:

put: TYPE A 
get: 200 Command TYPE okay. 
put: PASV 
get: 227 Entering Passive Mode (75,101,155,12,5,165) 
put: NLST * 
get: 150 File status okay; about to open data connection. 
get: 226 Closing data connection. 
put: TYPE I 
get: 200 Command TYPE okay. 
put: PASV 
get: 227 Entering Passive Mode (75,101,155,12,5,163) 
put: RETR <filename redacted> 
get: 150 File status okay; about to open data connection. 
get: 226 Transfer complete. 
...output from update processing 
put: PASV 
rake aborted! 
EOFError: end of file reached 
+0

'ftp.debug_mode = true'請啓用它並嘗試它 –

+0

@RajarshiDas它已被添加上面。謝謝。 –

回答

1

問題竟然是一個FTP閒置時間到。因爲UpdateVfile.loader是一個長期運行的任務,所以我離開了FTP很長時間,並且因爲EOFError而崩潰。很明顯,超時錯誤會比這種不重要的錯誤要好得多,因爲這樣的錯誤給了我比沒有診斷信息更糟的結果。

如果裝載機很短,它就起作用了。對於更強烈的更新,花費太長時間。當我更改源代碼來嘗試診斷並解決問題時,EOFError轉移到了ftp.delete命令,這對我來說更加沒有意義。

我發現了一些暗示這個問題的討論。因此,我在調用加載程序之前將我的進程更改爲處理所有FTP工作。這可靠地工作。否則,我不得不定期發送保活郵件或找到一種方法來修改超時時間。這兩者似乎都不容易實現。

如果有人能向我解釋爲什麼FTP會發出EOFError而不是超時錯誤,我會很高興。這是不對的,並會導致任何人完全錯誤的方向,診斷。謝謝...

相關問題