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

add a Remote field to the StreamError #139

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const WebTransportBufferedStreamRejectedErrorCode quic.StreamErrorCode = 0x3994b
// StreamError is the error that is returned from stream operations (Read, Write) when the stream is canceled.
type StreamError struct {
ErrorCode StreamErrorCode
Remote bool
}

func (e *StreamError) Is(target error) bool {
Expand Down
5 changes: 4 additions & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ func maybeConvertStreamError(err error) error {
if cerr != nil {
return fmt.Errorf("stream reset, but failed to convert stream error %d: %w", streamErr.ErrorCode, cerr)
}
return &StreamError{ErrorCode: errorCode}
return &StreamError{
ErrorCode: errorCode,
Remote: streamErr.Remote,
}
}
return err
}
Expand Down
12 changes: 12 additions & 0 deletions webtransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func TestMultipleClients(t *testing.T) {

func TestStreamResetError(t *testing.T) {
const errorCode webtransport.StreamErrorCode = 127
strChan := make(chan webtransport.Stream, 1)
sess, closeServer := establishSession(t, func(sess *webtransport.Session) {
for {
str, err := sess.AcceptStream(context.Background())
Expand All @@ -368,10 +369,12 @@ func TestStreamResetError(t *testing.T) {
}
str.CancelRead(errorCode)
str.CancelWrite(errorCode)
strChan <- str
}
})
defer closeServer()

// client side
str, err := sess.OpenStream()
require.NoError(t, err)
_, err = str.Write([]byte("foobar"))
Expand All @@ -381,6 +384,15 @@ func TestStreamResetError(t *testing.T) {
var strErr *webtransport.StreamError
require.True(t, errors.As(err, &strErr))
require.Equal(t, strErr.ErrorCode, errorCode)
require.True(t, strErr.Remote)

// server side
str = <-strChan
_, err = str.Read([]byte{0})
require.Error(t, err)
require.True(t, errors.As(err, &strErr))
require.Equal(t, strErr.ErrorCode, errorCode)
require.False(t, strErr.Remote)
}

func TestShutdown(t *testing.T) {
Expand Down