Skip to content

A failed flush keeps references the echo pattern then overwrites #6

Closed

Description

@aotodev

Problem

flush leaves the batch staged when sendmmsg fails, by design (the existing
test TransmitBatch.AFailedFlushLeavesTheBatchStaged pins this). stage keeps
references to the caller's bytes, and the README and echo.cpp stage straight out
of receive slots.

In the echo loop, a failed flush is logged and the loop continues:

  1. receive rearms and overwrites the slots the staged entries point into.
  2. New datagrams are staged after the old entries.
  3. The next flush sends the new peers' bytes to the old peers' addresses.

sendmmsg fails only when the first entry fails. A per-destination error that
repeats (EMSGSIZE, EPERM from netfilter, EACCES on broadcast,
EHOSTUNREACH) therefore fails every later flush too. The batch never drains,
and one bad destination stops replies to everyone.

Proposed fix

  • Example and README: discard() on any flush error, or at least on errors other
    than would_block, and say why in one line.
  • Library options, not mutually exclusive:
    • On an error other than EAGAIN, drop entry 0 and retry the rest in the same
      call. Report the dropped entry through the result.
    • Document the lifetime precisely: referenced bytes must stay put until a flush
      succeeds or discard() runs, not just "until flush returns".
  • Reconsider whether "stays staged on failure" should be the default for batches
    staged by reference.

Acceptance

A test where the first staged destination always fails shows the rest still go
out, or shows that the documented pattern recovers.

Activity

  1. self-assigned this
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions