Skip to content
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

Implement error codes spec #2927

Merged
merged 13 commits into from
Feb 9, 2025
Merged

Implement error codes spec #2927

merged 13 commits into from
Feb 9, 2025

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Aug 19, 2024

Specification: libp2p/specs#479

  • Update mplex to be interface compliant before merging

@sukunrt sukunrt force-pushed the sukun/error-codes branch 3 times, most recently from a6e85e0 to b7d79b0 Compare August 20, 2024 17:12
@sukunrt sukunrt force-pushed the sukun/error-codes branch 2 times, most recently from 66c8cdb to 53d436f Compare September 13, 2024 13:13
@MarcoPolo MarcoPolo mentioned this pull request Oct 28, 2024
26 tasks
@sukunrt sukunrt self-assigned this Oct 29, 2024
@sukunrt sukunrt force-pushed the sukun/error-codes branch 5 times, most recently from 3d1038b to aa8b049 Compare November 20, 2024 10:05
@sukunrt sukunrt mentioned this pull request Nov 20, 2024
10 tasks
@sukunrt sukunrt marked this pull request as ready for review November 21, 2024 13:16
@sukunrt sukunrt requested a review from MarcoPolo November 21, 2024 13:16
@MarcoPolo MarcoPolo mentioned this pull request Dec 5, 2024
20 tasks
Copy link
Collaborator

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

Looks good. Just a couple of small comments.

Do we have a PR that updates the WebRTC spec changes?


// ResetWithError closes both ends of the stream with errCode. The errCode is sent
// to the peer.
ResetWithError(errCode StreamErrorCode) error
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about CloseWithError as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need that? Close implies non error reliable close, no? For instance, we also flush all writes, and retransmit if necessary, when calling Close.

@@ -144,6 +144,22 @@ func (s *stream) Reset() error {
return nil
}

func (s *stream) ResetWithError(errCode network.StreamErrorCode) error {
// Cancel any pending reads/writes with an error.
// TODO: Should these be the other way round(remote=true)?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. The errors will be returned to the other side of the pipe. In this case the peer will see these errors, so we should set remote=true.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm removing support for error codes here. It's a much larger change. We need to propogate resets from read as well. I'll add it in a follow up PR.

if errors.As(err, &se) {
code := se.ErrorCode
if code > math.MaxUint32 {
// TODO(sukunrt): do we need this?
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably set the code to a sentinel value that signifies there was an error converting the transport code to a libp2p code. We also need to update the specs to mention this case (in case we haven't).

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a sentinel code. libp2p/specs@4eca305

@sukunrt sukunrt force-pushed the sukun/error-codes branch 3 times, most recently from 354fbdc to 798258c Compare January 27, 2025 15:22
@sukunrt sukunrt requested a review from MarcoPolo January 27, 2025 15:37
@sukunrt
Copy link
Member Author

sukunrt commented Jan 27, 2025

Should we add CloseReadWithError for streams? Only quic and webrtc support it.

I can introduce that in a follow up PR.

})
})

t.Run("StreamResetByConnCloseWithError", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should likely be called "NewStreamsErrByConnCloseWithError"

Copy link
Member Author

Choose a reason for hiding this comment

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

Split this into two

  1. Stream methods should get the connection close error code if the connection was closed.
  2. Conn.NewStream should get the connection close error code.

Copy link
Collaborator

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

A couple minor things to fix, but looks good!

@@ -56,6 +56,12 @@ func (s *stream) Reset() error {
return nil
}

func (s *stream) ResetWithError(_ network.StreamErrorCode) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please leave a comment with some context for why we can't do this yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

added some text.

@MarcoPolo MarcoPolo mentioned this pull request Jan 29, 2025
20 tasks
@sukunrt sukunrt merged commit 02ab795 into master Feb 9, 2025
9 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