Skip to content

netcore: configure requests to cancel on drop - #466

Merged
npry merged 1 commit into
mainfrom
npry/netcore.abort-on-drop
Nov 4, 2026
Merged

npry merged 1 commit into
mainfrom
npry/netcore.abort-on-drop

Conversation

@npry

@npry npry commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Per #447, netstack futures weren't cancel safe because we wouldn't check if the response channel was closed when processing the command. As a result, socket operations which were part of canceled futures would always complete, potentially throwing away received packets or accepts, or resending outgoing sends (all modulo caller logic, but this would be common in a select! loop).

This hadn't been resolved previously because netsock specifically depends on this behavior to ensure delivery of Close commands on socket drop without having to wait for a response.

Resolved by adding a flag to Request indicating the desired behavior (only nonblocking requests complete regardless of response channel state, while normal requests give up before trying to process the command). There is still a possible race if the caller drops the channel after we've started processing the command, but this isn't resolvable without implementing command rollback (i.e. to revert a command if it turns out the response couldn't be delivered, which seems more trouble than it's worth).

Closes #447

@npry
npry force-pushed the npry/netcore.abort-on-drop branch 4 times, most recently from 8e1afa8 to 57392f0 Compare October 29, 2026 14:14

@nrc nrc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one minor and not-strongly-held comment

@npry
npry force-pushed the npry/netcore.abort-on-drop branch 2 times, most recently from eef78f4 to c0eb6c3 Compare November 3, 2026 21:11
Per #447, netstack futures weren't cancel safe because we wouldn't check
if the response channel was closed when processing the command. As a
result, socket operations which were part of canceled futures would
previously always complete, potentially throwing away received packets
or accepts, or resending outgoing sends (all modulo caller logic, but
this would be common in a `select!` loop, especially with timers
involved).

This hadn't been resolved previously because netsock specifically
depends on this behavior to ensure delivery of `Close` commands on
socket drop without having to wait for a response.

Resolved by adding a flag to `Request` indicating the desired behavior
(only nonblocking requests complete regardless of response channel,
state, while normal requests give up before trying to process the
command). There is still a possible race if the caller drops the channel
after we've started processing the command, but this isn't resolvable
without implementing rollback in order to revert a command if it turns
out the response couldn't be delivered, which seems more trouble than
it's worth.

Closes #447

Signed-off-by: Nathan Perry <nathan@tailscale.com>
Change-Id: I071e8acce05fd9cc4fe3eb6cabdb9a6f6a6a6964
@npry
npry force-pushed the npry/netcore.abort-on-drop branch from c0eb6c3 to 9f7cec0 Compare November 3, 2026 21:13
@npry
npry merged commit 9f7cec0 into main Nov 4, 2026
23 checks passed
@npry
npry deleted the npry/netcore.abort-on-drop branch November 4, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

netstack: a cancelled recv leaves a blocked command that consumes the next datagram

2 participants