diff --git a/h2quic/server.go b/h2quic/server.go index ec35179b0..254786eeb 100644 --- a/h2quic/server.go +++ b/h2quic/server.go @@ -13,6 +13,7 @@ import ( "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/protocol" + "github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/utils" "golang.org/x/net/http2" "golang.org/x/net/http2/hpack" @@ -104,7 +105,12 @@ func (s *Server) handleStream(session streamCreator, stream utils.Stream) { var headerStreamMutex sync.Mutex // Protects concurrent calls to Write() for { if err := s.handleRequest(session, stream, &headerStreamMutex, hpackDecoder, h2framer); err != nil { - utils.Errorf("error handling h2 request: %s", err.Error()) + // QuicErrors must originate from stream.Read() returning an error. + // In this case, the session has already logged the error, so we don't + // need to log it again. + if _, ok := err.(*qerr.QuicError); !ok { + utils.Errorf("error handling h2 request: %s", err.Error()) + } return } } diff --git a/session.go b/session.go index fe2e5e01e..c40b8651f 100644 --- a/session.go +++ b/session.go @@ -417,8 +417,16 @@ func (s *Session) closeImpl(e error, remoteClose bool) error { e = qerr.PeerGoingAway } - utils.Errorf("Closing session with error: %s", e.Error()) - s.closeStreamsWithError(e) + quicErr := qerr.ToQuicError(e) + + // Don't log 'normal' reasons + if quicErr.ErrorCode == qerr.PeerGoingAway || quicErr.ErrorCode == qerr.NetworkIdleTimeout { + utils.Infof("Closing connection %x", s.connectionID) + } else { + utils.Errorf("Closing session with error: %s", e.Error()) + } + + s.closeStreamsWithError(quicErr) s.closeCallback(s.connectionID) if remoteClose { @@ -427,7 +435,6 @@ func (s *Session) closeImpl(e error, remoteClose bool) error { return nil } - quicErr := qerr.ToQuicError(e) if quicErr.ErrorCode == qerr.DecryptionFailure { // If we send a public reset, don't send a CONNECTION_CLOSE s.closeChan <- nil diff --git a/session_test.go b/session_test.go index ed7af2112..42ba531d9 100644 --- a/session_test.go +++ b/session_test.go @@ -381,10 +381,10 @@ var _ = Describe("Session", func() { Eventually(func() int { return runtime.NumGoroutine() }).Should(Equal(nGoRoutinesBefore)) n, err := s.Read([]byte{0}) Expect(n).To(BeZero()) - Expect(err).To(MatchError(testErr)) + Expect(err.Error()).To(ContainSubstring(testErr.Error())) n, err = s.Write([]byte{0}) Expect(n).To(BeZero()) - Expect(err).To(MatchError(testErr)) + Expect(err.Error()).To(ContainSubstring(testErr.Error())) }) }) @@ -603,7 +603,7 @@ var _ = Describe("Session", func() { Expect(err).NotTo(HaveOccurred()) Eventually(func() bool { return atomic.LoadUint32(&session.closed) != 0 }).Should(BeTrue()) _, err = s.Write([]byte{}) - Expect(err).To(MatchError(qerr.InvalidCryptoMessageType)) + Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.InvalidCryptoMessageType)) }) It("sends public reset after too many undecryptable packets", func() {