Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #46 from vishnugopal/fix-double-resume-error-on-co…

…nnection-errors

Fixes double resume error on connection errors
  • Loading branch information...
commit 01a3f3b07f37524bf0d0b78fa19916b4d8471861 2 parents 70fede9 + ed2afe3
@igrigorik igrigorik authored
Showing with 19 additions and 5 deletions.
  1. +9 −5 lib/em-synchrony/em-http.rb
  2. +10 −0 spec/http_spec.rb
View
14 lib/em-synchrony/em-http.rb
@@ -12,11 +12,15 @@ module HTTPMethods
def #{type}(options = {}, &blk)
f = Fiber.current
- conn = setup_request(:#{type}, options, &blk)
- conn.callback { f.resume(conn) }
- conn.errback { f.resume(conn) }
-
- Fiber.yield
+ conn = setup_request(:#{type}, options, &blk)
+ if conn.error.nil?
+ conn.callback { f.resume(conn) }
+ conn.errback { f.resume(conn) }
+
+ Fiber.yield
+ else
+ conn
+ end
end
]
end
View
10 spec/http_spec.rb
@@ -1,6 +1,7 @@
require "spec/helper/all"
URL = "http://localhost:8081/"
+CONNECTION_ERROR_URL = "http://random-domain-blah.com/"
DELAY = 0.25
describe EventMachine::HttpRequest do
@@ -58,4 +59,13 @@
EventMachine.stop
end
end
+
+ it "should terminate immediately in case of connection errors" do
+ EventMachine.synchrony do
+ response = EventMachine::HttpRequest.new(CONNECTION_ERROR_URL).get
+ response.error.should_not be_nil
+
+ EventMachine.stop
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.