Ruby - Imap server connection gets disconnected after 2 days even after being reconnected every 25 minutes -
i login imap server:
imap = net::imap.new("imap.gmail.com") imap.login("username", "password") imap.select("inbox")
and use imap idle fetch mails , when come. , since imap server connection automatically gets disconnected after 30 minutes, reconnect imap server every 25 minutes.
all works fine until goes on more 48 hours. following error when imap.logout
the error message:
ioerror closed stream - ["org/jruby/ext/openssl/sslsocket.java:664:in `syswrite'", "/opt/jruby-1.7.6/lib/ruby/shared/jopenssl19/openssl/buffering.rb:318:in `do_write'", "/opt/jruby-1.7.6/lib/ruby/shared/jopenssl19/openssl/buffering.rb:415:in `print'", /opt/jruby-1.7.6/lib/ruby/1.9/net/imap.rb:1210:in `put_string'", "/opt/jruby-1.7.6/lib/ruby/1.9/net/imap.rb:1182:in `send_command'", "/opt/jruby-1.7.6/lib/ruby/1.9/monitor.rb:211:in `mon_synchronize'", "/opt/jruby-1.7.6/lib/ruby/1.9/monitor.rb:210:in `mon_synchronize'", "/opt/jruby-1.7.6/lib/ruby/1.9/net/imap.rb:1177:in `send_command'", "/opt/jruby-1.7.6/lib/ruby/1.9/net/imap.rb:352:in `logout'"
the imap object:
#, raw_data="* ok gimap ready requests 54.242.66.175 v74mb152689693qgv\r\n">, @mon_owner=nil, @client_thread=#, @tagged_response_arrival=#, @cond=#>, @sock=#>, @sync_close=true, @rbuffer="", @hostname="", @io=#, @sync=true, @wbuffer="ruby0041 logoutruby0042 logoutruby0043 logoutruby0044 logoutruby0045 logoutruby0046 logoutruby0047 logoutruby0048 logoutruby0049 logoutruby0050 logoutruby0051 logoutruby0052 logoutruby0053 logoutruby0054 logoutruby0055 logout">, @tagno=55, @tagged_responses={}, @host="imap.gmail.com", @exception=nil, @usessl=true, @port=993, @tag_prefix="ruby", @mon_count=0, @receiver_thread=#, @responses={"flags"=>[[:answered, :flagged, :draft, :deleted, :seen, "$phishing", "$notphishing"]], "ok"=>[#, text=" flags permitted.">, #, text=" uids valid.">, #, text=" predicted next uid.">, #, text="">], "permanentflags"=>[[:answered, :flagged, :draft, :deleted, :seen, "$phishing", "$notphishing", :*]], "uidvalidity"=>[651870578], "exists"=>[1661], "recent"=>[0], "uidnext"=>[1835], "highestmodseq"=>["288129"], "bye"=>[#]}, @response_handlers=[], @continuation_request_arrival=#, @cond=#>, @receiver_thread_terminating=false, @logout_command_tag="ruby0040", @debug_output_bol=true, @parser=#true, :flagged=>true, :draft=>true, :deleted=>true, :seen=>true, :*=>true}, @token=nil, @str="ruby0040 ok 73 day (success)\r\n">, @mon_mutex=#, @idle_done_cond=#, @cond=#>>
can explain why happens?
if connection imap server closed when call logout
method, you'll error.
you can prevent checking connection before doing call
imap.logout unless imap.disconnected?
hope you.
Comments
Post a Comment