Skip to content

Commit

Permalink
When trapping the INT signal in order to return from the #response me…
Browse files Browse the repository at this point in the history
…thod,

it is possible to get into a state where it is still trapping even when the
method has returned, which results in a LocalJumpError.

I'm not convinced that trapping to return is the best thing to do but if
you do trap to return, you should restore the original trap when the method
exits.
  • Loading branch information
Luke Redpath authored and brianmario committed Jan 14, 2010
1 parent 5f115fe commit b198b4e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/yajl/http_stream.rb
Expand Up @@ -99,7 +99,7 @@ def self.request(method, uri, opts = {}, &block)
end

socket = opts.has_key?(:socket) ? opts.delete(:socket) : TCPSocket.new(uri.host, uri.port)
trap("INT") {
original_trap = trap("INT") {
return
}
request = "#{method} #{uri.path}#{uri.query ? "?"+uri.query : nil} HTTP/1.1\r\n"
Expand Down Expand Up @@ -183,6 +183,7 @@ def self.request(method, uri, opts = {}, &block)
end
end
ensure
trap("INT", original_trap) if original_trap
socket.close if !socket.nil? and !socket.closed?
end

Expand Down

0 comments on commit b198b4e

Please sign in to comment.