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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Implement error codes spec #2927

wants to merge 5 commits into from

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Aug 19, 2024

Specification: libp2p/specs#479

@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 4 times, most recently from f60e35b to 3d1038b Compare November 20, 2024 06:17
@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
23 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?

@@ -61,6 +101,13 @@ type MuxedStream interface {
SetWriteDeadline(time.Time) error
}

type ResetWithErrorer interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not add this to the MuxedStream Interface? I'm worried that this approach will have the following issues:

  • Every usage will need to do an interface check to do this.
  • If we wrap the stream or conn, we could easily forget to also implement these interfaces and silently drop this ability.


// 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?

if errors.As(err, &ce) {
return &network.ConnError{Remote: ce.Remote, ErrorCode: network.ConnErrorCode(ce.ErrorCode)}
}
// TODO: How should we handle resets for reason other than a remote error
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this TODO, can you elaborate?

@@ -33,6 +33,14 @@ func (c *tconn) Close() error {
return nil
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a test here that the remote gets the expected error back?

@@ -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.

return
}
_, err = s.Read(b)
fmt.Println(err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

debug vestige?

err = s.ResetWithError(42)
require.NoError(t, err)

_, err = s.Read(buf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

How common is it to read/write to a stream after resetting it? That seems like a logic error to me.

s, err := client.NewStream(ctx, server.ID(), "/test")
require.NoError(t, err)

_, err = s.Write([]byte("hello"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: It seems like all these tests do this simple echo. Can we move that logic to a separate fn and have the test code be a bit smaller?

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).

return s.closeRead(0, false)
}

func (s *stream) closeRead(errCode network.StreamErrorCode, remote bool) error {
s.mx.Lock()
defer s.mx.Unlock()
var err error
if s.receiveState == receiveStateReceiving && s.closeForShutdownErr == nil {
err = s.writer.WriteMsg(&pb.Message{Flag: pb.Message_STOP_SENDING.Enum()})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this missing the error code in the pb Message? Why didn't the transport test catch this?

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