Skip to content

proto: provide reason when refusing connections #2235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

djc
Copy link
Member

@djc djc commented May 12, 2025

No description provided.

@djc djc requested review from Ralith and gretchenfrage as code owners May 12, 2025 09:19
pub fn refuse_reason(
&mut self,
incoming: Incoming,
reason: Option<String>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Connection::close takes Bytes. Should we do the same here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? ApplicationClose::reason is (publicly) Bytes but TransportError::reason is (publicly) String -- I feel like String is probably more reasonable in terms of the public API, and it doesn't feel like there's a bunch of performance to be had from refcounting error reasons instead of allocating?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It gets baked down into ConnectionClose::reason, which exactly mirrors ApplicationClose::reason as Bytes, and is not strictly required to be UTF-8. The involvement of TransportError is an artifact of the private initial_close API, which we can easily revisit. Most important, though, is just that it would be more consistent with close, which is morally the same operation, just at a different time.

Copy link
Member Author

Choose a reason for hiding this comment

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

RFC 9000, section 19.19:

  • Reason Phrase: Additional diagnostic information for the closure. This can be zero length if the sender chooses not to give details beyond the Error Code value. This SHOULD be a UTF-8 encoded string [RFC3629], though the frame does not carry information, such as language tags, that would aid comprehension by any entity other than the one that created the text.

Which makes me feel that String is a better API than Bytes.

@djc djc force-pushed the refuse-reason branch from a66db67 to fb68759 Compare May 14, 2025 10:37
@djc djc force-pushed the refuse-reason branch from fb68759 to 599da42 Compare May 14, 2025 10:38
@djc
Copy link
Member Author

djc commented May 26, 2025

@gretchenfrage you mentioned you want to review this -- friendly ping?

@gretchenfrage
Copy link
Collaborator

Sorry, I hadn't meant to block this as long as I have! I'll try not to much longer.

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.

3 participants