Skip to content

A queued plaintext write has no deadline, so a peer that stops reading holds the connection forever #223

Closed

Description

@EdmondDantes

What the code does

http_write_timer_arm has three callers: the two awaited senders
(src/core/http_connection.c:1376, :1465) and http1_stream.c:335 through
http_connection_arm_write_deadline, which #179 added for exactly this reason —
"queued bytes carry no await to time out".

The batched senders arm nothing. http_connection_send_batched,
http_connection_send_zstr_batched and http_connection_send_batched_writev
submit and return; http_send_batched_finish only ever stops the timer.
Every plaintext HTTP/2 response goes out that way (h2_emit_flush_h2c), and
since #209 and #211 so do the HTTP/1 fire-and-forget senders.

http_connection.h:511-512 already names the hazard in words: "a write to a
peer that stopped reading never completes, and the destroy that defers on
out_in_flight never runs."

What follows

A peer that stops reading without closing wedges the writev. out_in_flight
stays true, and:

  • http_connection_destroy defers at src/core/http_connection.c:360;
  • the deadline sweep (src/http_server_class.c:862) calls
    http_connection_destroy on every tick and it re-defers each time, so the
    connection, its io and its read buffer are never reclaimed;
  • since HTTP/2 h2c: the read path drains the session at the socket and loses response bytes #219 the read path leans on the same flag: http2_session_emit skips
    while out_in_flight (src/http2/http2_strategy.c:1541), so SETTINGS ACK,
    PING ACK, WINDOW_UPDATE and the winding-down teardown stop with the response.

One wedged peer per held connection, with no upper bound.

Fix

Arm the connection's write deadline at submit in the batched senders, the way
http1_stream.c:335 does for the queued tryWrite() path. The timer is already
stopped by http_send_batched_finish when the chain ends.

This changes HTTP/1 as well as HTTP/2 — a batched response to a peer that stops
reading is now bounded by setWriteTimeout (30 s by default) — so it wants its
own test rather than riding along with #219.

Found while reviewing #219 (PR 220).

Activity

  1. added this to the Next3 milestone on Aug 22, 2026
  2. added a commit that references this issue on Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions