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

http3: ignore deadline errors when tracking QUIC stream states #4495

Merged
merged 1 commit into from
May 7, 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
5 changes: 3 additions & 2 deletions http3/state_tracking_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package http3
import (
"context"
"errors"
"os"
"sync"

"github.com/quic-go/quic-go"
Expand Down Expand Up @@ -75,7 +76,7 @@ func (s *stateTrackingStream) CancelWrite(e quic.StreamErrorCode) {

func (s *stateTrackingStream) Write(b []byte) (int, error) {
n, err := s.Stream.Write(b)
if err != nil {
if err != nil && !errors.Is(err, os.ErrDeadlineExceeded) {
s.closeSend(err)
}
return n, err
Expand All @@ -88,7 +89,7 @@ func (s *stateTrackingStream) CancelRead(e quic.StreamErrorCode) {

func (s *stateTrackingStream) Read(b []byte) (int, error) {
n, err := s.Stream.Read(b)
if err != nil {
if err != nil && !errors.Is(err, os.ErrDeadlineExceeded) {
s.closeReceive(err)
}
return n, err
Expand Down
52 changes: 51 additions & 1 deletion http3/state_tracking_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"io"
"os"

"github.com/quic-go/quic-go"
mockquic "github.com/quic-go/quic-go/internal/mocks/quic"
Expand Down Expand Up @@ -43,7 +44,7 @@ var _ = Describe("State Tracking Stream", func() {
Expect(states[0].err).To(Equal(io.EOF))
})

It("recognizes read cancellations", func() {
It("recognizes local read cancellations", func() {
qstr := mockquic.NewMockStream(mockCtrl)
qstr.EXPECT().StreamID().AnyTimes()
qstr.EXPECT().Context().Return(context.Background()).AnyTimes()
Expand All @@ -64,6 +65,39 @@ var _ = Describe("State Tracking Stream", func() {
Expect(states[0].err).To(Equal(&quic.StreamError{ErrorCode: 1337}))
})

It("recognizes remote cancellations", func() {
qstr := mockquic.NewMockStream(mockCtrl)
qstr.EXPECT().StreamID().AnyTimes()
qstr.EXPECT().Context().Return(context.Background()).AnyTimes()
var states []stateTransition
str := newStateTrackingStream(qstr, func(state streamState, err error) {
states = append(states, stateTransition{state, err})
})

testErr := errors.New("test error")
qstr.EXPECT().Read(gomock.Any()).Return(0, testErr)
_, err := str.Read(make([]byte, 3))
Expect(err).To(MatchError(testErr))
Expect(states).To(HaveLen(1))
Expect(states[0].state).To(Equal(streamStateReceiveClosed))
Expect(states[0].err).To(MatchError(testErr))
})

It("doesn't misinterpret read deadline errors", func() {
qstr := mockquic.NewMockStream(mockCtrl)
qstr.EXPECT().StreamID().AnyTimes()
qstr.EXPECT().Context().Return(context.Background()).AnyTimes()
var states []stateTransition
str := newStateTrackingStream(qstr, func(state streamState, err error) {
states = append(states, stateTransition{state, err})
})

qstr.EXPECT().Read(gomock.Any()).Return(0, os.ErrDeadlineExceeded)
_, err := str.Read(make([]byte, 3))
Expect(err).To(MatchError(os.ErrDeadlineExceeded))
Expect(states).To(BeEmpty())
})

It("recognizes when the send side is closed, when write errors", func() {
qstr := mockquic.NewMockStream(mockCtrl)
qstr.EXPECT().StreamID().AnyTimes()
Expand All @@ -86,6 +120,22 @@ var _ = Describe("State Tracking Stream", func() {
Expect(states[0].err).To(Equal(testErr))
})

It("recognizes when the send side is closed, when write errors", func() {
qstr := mockquic.NewMockStream(mockCtrl)
qstr.EXPECT().StreamID().AnyTimes()
qstr.EXPECT().Context().Return(context.Background()).AnyTimes()
var states []stateTransition
str := newStateTrackingStream(qstr, func(state streamState, err error) {
states = append(states, stateTransition{state, err})
})

qstr.EXPECT().Write([]byte("foo")).Return(0, os.ErrDeadlineExceeded)
Expect(states).To(BeEmpty())
_, err := str.Write([]byte("foo"))
Expect(err).To(MatchError(os.ErrDeadlineExceeded))
Expect(states).To(BeEmpty())
})

It("recognizes when the send side is closed, when CancelWrite is called", func() {
qstr := mockquic.NewMockStream(mockCtrl)
qstr.EXPECT().StreamID().AnyTimes()
Expand Down
Loading