From 2cdf0ad509da66fe9f2a89ae76550a80f397d948 Mon Sep 17 00:00:00 2001 From: Adrianna Chang Date: Wed, 16 Jul 2025 12:16:48 -0400 Subject: [PATCH] Execute `rack.response_finished` callbacks in reverse order of registration This matches the SPEC: https://github.com/rack/rack/blob/main/SPEC.rdoc#rackresponse_finished- --- CHANGELOG.md | 1 + lib/pitchfork/http_server.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5619896..e184acb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Fix a regression introduced in `0.17.0` causing `before_worker_exit` to often not be called. - Implemented the `max_consecutive_spawn_errors` configuration. Purely opt-in for now. - Properly handle magic comments in `config.ru`. +- Execute `rack.response_finished` callbacks in reverse order of registration # 0.17.0 diff --git a/lib/pitchfork/http_server.rb b/lib/pitchfork/http_server.rb index ca56bfbf..8cca7971 100644 --- a/lib/pitchfork/http_server.rb +++ b/lib/pitchfork/http_server.rb @@ -893,7 +893,7 @@ def process_client(client, worker, timeout_handler) env ensure if env - env["rack.response_finished"].each do |callback| + env["rack.response_finished"].reverse_each do |callback| if callback.arity == 0 callback.call else