#4003·puma

Path-backed response file leaks when socket writes fail

Author: OskarEichlerCreated Aug 30, 2026Updated Aug 30, 2026

When a Rack response body exposes to_path, Puma opens a separate File for the fast response path and closes it only after fast_write_response returns successfully. If the socket write raises Errno::EPIPE or Puma::ConnectionError, the outer response cleanup closes the original Rack body, not the separately opened file.

A narrow source fix wraps fast_write_response in begin/ensure and closes the opened response file in the ensure path.

A standalone model tracks the path-backed file handle and forces a write failure. Puma 8.0.2/current report response file leaked; the candidate closes it while preserving the primary write exception.

Local verification: focused upstream test_response_header:test_rack_server passes 28 runs /67 assertions; the changed file passes Ruby syntax and project RuboCop. I am filing issue-first because CONTRIBUTING asks code fixes to include tests.