Skip to content

Commit

Permalink
Fix off-by-one for requests_count during after_request_complete
Browse files Browse the repository at this point in the history
The increment only happens after which made it lag behind
  • Loading branch information
Earlopain committed May 8, 2024
1 parent 37a0f9d commit 37c55e1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pitchfork/http_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,8 @@ def worker_loop(worker)
worker.update(client)
else
request_env = process_client(client, worker, prepare_timeout(worker))
@after_request_complete&.call(self, worker, request_env)
worker.increment_requests_count
@after_request_complete&.call(self, worker, request_env)
end
worker.update_deadline(@timeout)
end
Expand Down
6 changes: 2 additions & 4 deletions test/integration/test_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ def test_after_request_complete
listen "#{addr}:#{port}"
worker_processes 1
request_count = 0
after_request_complete do |server, worker, env|
request_count += 1
$stderr.puts "[after_request_complete] request_count=\#{request_count} path=\#{env['PATH_INFO']}"
$stderr.puts "[after_request_complete] worker_requests_count=\#{worker.requests_count} path=\#{env['PATH_INFO']}"
end
before_worker_exit do |server, worker|
Expand All @@ -21,7 +19,7 @@ def test_after_request_complete
CONFIG

assert_healthy("http://#{addr}:#{port}")
assert_stderr("[after_request_complete] request_count=1 path=/")
assert_stderr("[after_request_complete] worker_requests_count=1 path=/")
assert_healthy("http://#{addr}:#{port}")

assert_clean_shutdown(pid)
Expand Down

0 comments on commit 37c55e1

Please sign in to comment.