Skip to content

Commit

Permalink
Handle errors in rack.after_reply
Browse files Browse the repository at this point in the history
Ref: #97

Don't break the callback chain if one callback raised.
  • Loading branch information
byroot committed Mar 11, 2024
1 parent b101411 commit a410482
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
# Unreleased

- Don't break the `rack.after_reply` callback chain if one callback raises (#97).

# 0.11.1

- Fix Ruby 3.4-dev compatibility.
Expand Down
8 changes: 7 additions & 1 deletion lib/pitchfork/http_server.rb
Expand Up @@ -762,7 +762,13 @@ def process_client(client, worker, timeout_handler)
handle_error(client, e)
env
ensure
env["rack.after_reply"].each(&:call) if env
if env
env["rack.after_reply"].each do |callback|
callback.call
rescue => error
Pitchfork.log_error(@logger, "rack.after_reply error", error)
end
end
timeout_handler.finished
env
end
Expand Down
1 change: 1 addition & 0 deletions test/slow/test_server.rb
Expand Up @@ -41,6 +41,7 @@ def call(env)
while env['rack.input'].read(4096)
end

env["rack.after_reply"] << -> { raise "oops" }
env["rack.after_reply"] << -> { @called = true }

[200, { 'content-type' => 'text/plain' }, ["after_reply_called: #{@called}"]]
Expand Down

0 comments on commit a410482

Please sign in to comment.