Skip to content

The lingering close has no TLS path: https loses its 413 and wss loses its 1013 #311

Description

@EdmondDantes

A socket closed while the peer still has unread bytes in its receive buffer is
reset rather than finished, and the reset discards what this side has written
but the peer has not read. #288 answered that for plaintext HTTP/1 with a
lingering close; #305 armed the same drain from the WebSocket inbound-cap
teardown. Neither reaches a TLS connection.

The drain is fed from the plaintext read paths alone —
http_connection_linger_note_inbound is reached from http_connection.c:1324
and :1429, and http_connection_tls.c does not mention the drain at all. A
TLS connection that armed it would wait with nothing being read and close on the
same unread bytes at the end, so http_connection_linger_begin refuses one
outright rather than spending the deadline for nothing.

That refusal is the honest state, not the fix. Over TLS:

Both are the disclosure of nothing rather than of something — the client learns
no reason for the connection ending, which is exactly what the lingering close
exists to prevent.

What closing it takes

The TLS read FSM needs the drop-and-refresh hook the plaintext paths have: while
conn->linger_close is set, ciphertext that arrives is decrypted and thrown
away rather than buffered, and each chunk pushes deadline_ms out by one idle
window. Then linger_begin can stop refusing.

Read tls_advance_state in src/core/http_connection_tls.c alongside the
plaintext sites above: the one-shot TLS read is not re-armed once
tls_finalize_if_closing returns true, so the drain needs a re-arm there as
well as the drop.

Feedback loop

websocket/035-recv-queue-overflow proves the plaintext half today. The TLS half
has no test: a wss copy of 035 — same flood, same cap, listener with
enableTls(true) — is the loop, and it should read client saw close: NULL
before the fix. Run it outside run-tests or without usleep(/microtime( in
its FILE section, or the retry will report only the second attempt (#TBD).

Found by the review of #305.

Activity

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions