Skip to content
Browse files

require SystemTimer gem to prevent IO timeouts due to a bug in Ruby's…

… IMAP implementation
  • Loading branch information...
1 parent d1a1363 commit 7ebbaa89ae450726f0399e62681bb477bc5bc38f @look committed
Showing with 11 additions and 5 deletions.
  1. +11 −5 lib/fetcher/imap.rb
View
16 lib/fetcher/imap.rb
@@ -1,3 +1,4 @@
+require 'system_timer'
require File.dirname(__FILE__) + '/../vendor/plain_imap'
module Fetcher
@@ -26,11 +27,16 @@ def initialize(options={})
# Open connection and login to server
def establish_connection
- @connection = Net::IMAP.new(@server, @port, @ssl)
- if @use_login
- @connection.login(@username, @password)
- else
- @connection.authenticate(@authentication, @username, @password)
+ # Work around a freezing bug in Ruby's IMAP implementation using the SystemTimer library.
+ # It will have a SIGALRM sent to the process if this block doesn't exit in 15 seconds.
+ # Ruby's timeout's are unreliable if a system call is invoked.
+ SystemTimer.timeout_after(15.seconds) do
+ @connection = Net::IMAP.new(@server, @port, @ssl)
+ if @use_login
+ @connection.login(@username, @password)
+ else
+ @connection.authenticate(@authentication, @username, @password)
+ end
end
end

0 comments on commit 7ebbaa8

Please sign in to comment.
Something went wrong with that request. Please try again.