Skip to content

lanlord: read a refusal even if sending the request failed - #29

Merged
bradfitz merged 1 commit into
mainfrom
bradfitz/lanlord-flake
Nov 26, 2026
Merged

bradfitz merged 1 commit into
mainfrom
bradfitz/lanlord-flake

Conversation

@bradfitz

@bradfitz bradfitz commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

A Server may refuse a caller, by uid, before reading its request, and
then replies and closes. If that close won the race with the client's
write of its request, the write failed with EPIPE, and DialContext
returned "sending request: write: broken pipe" without reading the
reply that said why. A disallowed user would see that instead of "not
allowed", and TestRefusals/uid flaked on ubuntu-latest in CI.

Fix it in the Client rather than the Server, to keep the root side as
simple as possible. After a failed write, read the reply anyway, since
what the server wrote before closing is still readable, and report the
write error only if there is no reply. A write that failed because of
the context still returns the context's error at once.

go test -count=3000 -cpu=1,2,4 -run TestRefusals/uid reproduced the
failure before. With this, it passes, including runs where the write
got EPIPE.

Updates tailscale/corp#51929

@bradfitz
bradfitz requested a review from a team November 26, 2026 16:02

@tomhjp tomhjp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This works, but ideally I think it would be better to work around it on the less security sensitive side of the connection instead

Comment thread lanlord/lanlord.go Outdated
}
// Read the request before any refusal. If the server replied and
// closed before the client finished writing, the client's write could
// fail with EPIPE and it would never see the reason.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On principle, I'd prefer to keep the server side logic as simple as possible and fix this on the client side. The initial client request write might fail if it already got closed, but it should still be able to read the server's reply

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, will do.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(part of me says it's silly to care on a mac where they're almost never multi-user with a mix of trusted users and untrusted users, but the fix is easy enough....)

A Server may refuse a caller, by uid, before reading its request, and
then replies and closes. If that close won the race with the client's
write of its request, the write failed with EPIPE, and DialContext
returned "sending request: write: broken pipe" without reading the
reply that said why. A disallowed user would see that instead of "not
allowed", and TestRefusals/uid flaked on ubuntu-latest in CI.

Fix it in the Client rather than the Server, to keep the root side as
simple as possible. After a failed write, read the reply anyway, since
what the server wrote before closing is still readable, and report the
write error only if there is no reply. A write that failed because of
the context still returns the context's error at once.

go test -count=3000 -cpu=1,2,4 -run TestRefusals/uid reproduced the
failure before. With this, it passes, including runs where the write
got EPIPE.

Updates tailscale/corp#51929

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change-Id: I17ffa4ec13b068ce572b060f7bac2e01afe29921
@bradfitz
bradfitz force-pushed the bradfitz/lanlord-flake branch from 995731a to eb36f3c Compare November 26, 2026 21:20
@bradfitz bradfitz changed the title lanlord: read the request before refusing it lanlord: read a refusal even if sending the request failed Nov 26, 2026
@bradfitz
bradfitz merged commit 413cbbc into main Nov 26, 2026
4 checks passed
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.

2 participants