introduce a qerr.Err{Idle,Handshake}Timeout

This commit is contained in:
Marten Seemann
2021-03-22 14:22:36 +08:00
parent 81d16a9903
commit 154b55b50a
3 changed files with 10 additions and 5 deletions

View File

@@ -5,6 +5,11 @@ import (
"net" "net"
) )
var (
ErrIdleTimeout = newTimeoutError("No recent network activity")
ErrHandshakeTimeout = newTimeoutError("Handshake did not complete in time")
)
// A QuicError consists of an error code plus a error reason // A QuicError consists of an error code plus a error reason
type QuicError struct { type QuicError struct {
ErrorCode ErrorCode ErrorCode ErrorCode
@@ -33,8 +38,8 @@ func NewErrorWithFrameType(errorCode ErrorCode, frameType uint64, errorMessage s
} }
} }
// NewTimeoutError creates a new QuicError instance for a timeout error // newTimeoutError creates a new QuicError instance for a timeout error
func NewTimeoutError(errorMessage string) *QuicError { func newTimeoutError(errorMessage string) *QuicError {
return &QuicError{ return &QuicError{
ErrorMessage: errorMessage, ErrorMessage: errorMessage,
isTimeout: true, isTimeout: true,

View File

@@ -31,7 +31,7 @@ var _ = Describe("QUIC Transport Errors", func() {
}) })
It("has a string representation for timeout errors", func() { It("has a string representation for timeout errors", func() {
err := NewTimeoutError("foobar") err := newTimeoutError("foobar")
Expect(err.Timeout()).To(BeTrue()) Expect(err.Timeout()).To(BeTrue())
Expect(err.Error()).To(Equal("NO_ERROR: foobar")) Expect(err.Error()).To(Equal("NO_ERROR: foobar"))
}) })

View File

@@ -667,7 +667,7 @@ runLoop:
if s.tracer != nil { if s.tracer != nil {
s.tracer.ClosedConnection(logging.NewTimeoutCloseReason(logging.TimeoutReasonHandshake)) s.tracer.ClosedConnection(logging.NewTimeoutCloseReason(logging.TimeoutReasonHandshake))
} }
s.destroyImpl(qerr.NewTimeoutError("Handshake did not complete in time")) s.destroyImpl(qerr.ErrHandshakeTimeout)
continue continue
} else { } else {
idleTimeoutStartTime := s.idleTimeoutStartTime() idleTimeoutStartTime := s.idleTimeoutStartTime()
@@ -676,7 +676,7 @@ runLoop:
if s.tracer != nil { if s.tracer != nil {
s.tracer.ClosedConnection(logging.NewTimeoutCloseReason(logging.TimeoutReasonIdle)) s.tracer.ClosedConnection(logging.NewTimeoutCloseReason(logging.TimeoutReasonIdle))
} }
s.destroyImpl(qerr.NewTimeoutError("No recent network activity")) s.destroyImpl(qerr.ErrIdleTimeout)
continue continue
} }
} }