Connection: close header not sent before closing HTTP 1.1 connection when a controller raises an exception
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
Research direction
Start with lib/phoenix/endpoint/render_errors.ex and the linked Phoenix Bandit reproduction, then trace the response through Bandit’s HTTP/1 socket, pipeline, and handler paths named in the report. Run phoenix_bandit_repro.exs.zip and verify that an error response followed by connection closure advertises Connection: close before the socket closes.
Written by the indexing model from the issue text.
Description
Environment
-
Elixir version (elixir -v): 1.20.4
Erlang/OTP 28 [erts-16.4.0.6] [source] [64-bit] [smp:14:14] [ds:14:14:10] [async-threads:1] [jit]
Elixir 1.20.4 (compiled with Erlang/OTP 28) -
Phoenix version (mix deps): 1.8.15
-
Bandit version: 1.12.5
-
Operating system: macOS 26.7.1
Background
While fuzz-testing our HTTP API with Schemathesis, we found that sequences including syntactically valid HTTP/1.1 requests containing invalid API input, such as GET /api/items?limit=not-a-number that results in a 400 response, sometimes produces a subsequent connection-reuse error.
Actual behavior
When processing a HTTP 1.1 request, raising a Plug.BadRequestError in the controller results in a complete HTTP 400 response, after which the TCP connection is closed without a prior HTTP Connection: close header.
Code sequence
- Phoenix renders the error response, then re-raises. Its rendering path does not add Connection: close.
- When sending the headers, Bandit selects the HTTP/1.1 keep-alive path.
- Bandit catches the re-raised exception and returns an error. Its already-sent response check correctly avoids sending another response, but consequently skips sending a Connection: close.
- Bandit’s HTTP/1 handler closes the connection on that error
Expected behavior
The server sends a Connection: close header when the server knows it will close the connection immediately afterward the HTTP response.
RFC 9112 §9.6 says a server SHOULD include the Connection: close header when it intends to close the connection. While this is a SHOULD, not a MUST level item, explicitly advertising closure improves compatibility with conformance testing tools and HTTP clients in the wild.
- Dominant language
- Elixir
- Stars
- 23.2k
- Forks
- 3.2k
- Avg merge
- 16h 35m
- Merged PRs (30d)
- 18
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phoenixframework/phoenix
-
Binary pushes don't work over the LongPoll transportPossibly taken @mandar1045 claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
phoenixframework/phoenix#6906 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 56/100
phoenixframework/phoenix#6898 · 3 comments ·
Maintainers usually reply within 1 day
-
~p treats routes as static when they only start with a static directory namePossibly taken @mandar1045 claimed this 12 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 30/100
phoenixframework/phoenix#6895 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
phoenixframework/phoenix#6853 · 4 comments ·
Maintainers usually reply within 1 day
-
LongPoll session tokens are not bound to the mount path or socket handlerPossibly taken @SteffenDE claimed this 86 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 52/100
phoenixframework/phoenix#6791 · 1 comment ·
Maintainers usually reply within 1 day
All issues in phoenixframework/phoenix
Similar issues
-
Bug: Table layout and date column are cut off on mobile screens on the Tournaments -> History pageOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
hexlet-codebattle/codebattle#2375 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wintermeyer/vutuv#2388 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Broadcast API docs say to prepend realtime: to the topic, which breaks deliveryPossibly taken @mandar1045 claimed this 1 day ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
phoenixframework/phoenix_live_view#4509 ·
Maintainers usually reply within 1 day