Skip to content

sim(network): data that lands on a peer that closed its socket is dropped with no RST #204

Open

Description

@PierreZ

Follow-up to #202. With the end-to-end window in place, the way a closed peer handles arriving bytes became an explicit choice, and the choice made there is the conservative one: keep today's behavior.

Current behavior

In NetworkSimulation::land (crates/moonpool-sim/src/network/sim/engine.rs), a data chunk that lands on a receiver whose is_closed or recv_closed flag is set is dropped and its window credit is released back to the writer. The writer never learns anything: poll_write keeps succeeding, poll_read sees the FIN and EOF, and the bytes go nowhere.

That is what a kernel does for shutdown(SHUT_RD) (discard and ACK), so the recv_closed arm is right. It is not what happens when the peer has fully closed the socket: real TCP answers data arriving at a closed socket with RST, and the writer's next write (or read) fails with ECONNRESET/EPIPE. Today a client that keeps streaming into a server that closed its socket after replying never sees an error, and a bug in the client's "server went away" handling is invisible.

Requested behavior

When a data chunk lands on a receiver with is_closed set (a full close, not just recv_closed):

  • abort the sender's endpoint with CloseReason::Aborted, so the next write fails ConnectionReset and a writer parked on the window wakes to it (the abort path already does the wake);
  • the sender's receive side should also see the reset: Linux discards the unread receive buffer on RST, which is the classic "connection reset by peer, lost the response" failure. This is the disruptive half and needs its own test coverage on the hyper/h2 suites, since HTTP/1.1 and h2 graceful-close paths depend on reading trailing data after the peer's FIN.

Whether to also reset when the arriving item is a FIN (a close crossing a close) is the simultaneous-close case and can stay as is.

Constraints

  • No new randomness: the reset is a deterministic consequence of state, not a fault family.
  • Must not regress h2_partition_integrity, hyper_http, or the recovery-mode tests that rely on half-close semantics.
  • Keep the recv_closed-only arm discarding and releasing, as it does now.

Acceptance

  • Test: server reads the request, writes a reply, drops its stream; client writes again after the FIN landed; client's write (or the one after) fails with ConnectionReset, and a client parked on a full window is woken to that error rather than left waiting.
  • Test: close_connection_asymmetric(recv only) peer still discards silently.
  • Existing suites green.

Activity

  1. changed the title [-]sim(network): writes to a peer that already closed are discarded instead of answered with RST[/-] [+]sim(network): data that lands on a peer that closed its socket is dropped with no RST[/+] on Nov 16, 2026
  2. added
    bug
    on Nov 16, 2026
  3. PierreZ commented on Nov 16, 2026

    @PierreZ
    OwnerAuthor

    Triage 2026-11-16 (approved by Pierre): narrowed, half of it is done.

    Done on main since this issue was filed:

    • A dead process answers the first data or FIN that reaches it with one RST (reset_on_arrival, crates/moonpool-sim/src/network/sim/delivery.rs, land).
    • A close after a send-side cut sends an RST instead of a FIN (close_graceful, engine.rs).

    Still open, and the new scope of this issue:

    1. Data that lands on a peer that closed its socket on purpose (is_closed, not only recv_closed) is dropped, and its window credit is released. The writer never sees an error. Requested: the receiver answers with an RST, so the writer's next write fails with ConnectionReset and a writer parked on the window wakes to that error. Keep the recv_closed-only arm as it is (discard and release).
    2. A close with unread bytes in the receive buffer sends a FIN today (close_graceful discards the buffer, then queues a FIN). Linux sends an RST in this case. Requested: the same.

    FoundationDB reference: Sim2Conn::closeInternal calls peer->peerClosed(), and the peer stops receiving one second later, so its writes fail (sim2.actor.cpp, peerClosed, closeInternal).

    The constraints and the acceptance tests in the description stay. Labels: sim-network, bug, normal. Bundle: do together with #203.


    Generated by Claude Code

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

    bugnormalsim-network

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions