Skip to content

Commit

Permalink
Rescue all types of errors when processing request
Browse files Browse the repository at this point in the history
[#62 state:resolved]
  • Loading branch information
macournoyer committed Apr 19, 2008
1 parent 79f2a32 commit a9acdec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
== 0.8.1 Rebel Porpoise release
* [bug] Rescue all types of errors when processing request, fixes #62
* [bug] Use Swiftiply backend when -y option is specified, fixes #63 and #64
* Allow passing port as a string in Server.new
* Define deferred?(env) in your Rack application to set if a request is handled in a
Expand Down
6 changes: 3 additions & 3 deletions lib/thin/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def pre_process

# Process the request calling the Rack adapter
@app.call(@request.env)
rescue
rescue Object
handle_error
terminate_request
nil # Signal to post_process that the request could not be processed
Expand All @@ -80,7 +80,7 @@ def post_process(result)
# If no more request on that same connection, we close it.
close_connection_after_writing unless persistent?

rescue
rescue Object
handle_error
ensure
terminate_request
Expand Down Expand Up @@ -133,7 +133,7 @@ def threaded?
# IP Address of the remote client.
def remote_address
@request.forwarded_for || socket_address
rescue
rescue Object
log_error
nil
end
Expand Down
10 changes: 10 additions & 0 deletions spec/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
@connection.process
end

it "should rescue error in process" do
@connection.app.should_receive(:call).and_raise(StandardError)
@connection.process
end

it "should rescue Timeout error in process" do
@connection.app.should_receive(:call).and_raise(Timeout::Error.new("timeout error not rescued"))
@connection.process
end

it "should return HTTP_X_FORWARDED_FOR as remote_address" do
@connection.request.env['HTTP_X_FORWARDED_FOR'] = '1.2.3.4'
@connection.remote_address.should == '1.2.3.4'
Expand Down

0 comments on commit a9acdec

Please sign in to comment.