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

Return error conforming to net.Error for timeouts #76

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 9 additions & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ var (
ErrInvalidProtocol = errors.New("invalid protocol")
ErrConsumed = errors.New("peer consumed more than sent")
ErrGoAway = errors.New("stream id overflows, should start a new connection")
ErrTimeout = errors.New("timeout")
ErrTimeout = &timeoutError{}
ErrWouldBlock = errors.New("operation would block on IO")
)

var _ net.Error = &timeoutError{}

type timeoutError struct{}

func (e *timeoutError) Error() string { return "timeout" }
func (e *timeoutError) Timeout() bool { return true }
func (e *timeoutError) Temporary() bool { return true }

type writeRequest struct {
prio uint64
frame Frame
Expand Down
10 changes: 10 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,16 @@ func TestWriteFrameInternal(t *testing.T) {
if !strings.Contains(err.Error(), "timeout") {
t.Fatal("write frame with deadline failed", err)
}
netErr, ok := err.(net.Error)
if !ok {
t.Fatal("expected net.Error for timeout")
}
if netErr.Timeout() == false {
t.Fatal("expected Timeout() to be true on timeout error ", err)
}
if netErr.Temporary() == false {
t.Fatal("expected Temporary() to be true on timeout error", err)
}
}
cli.Close()

Expand Down