improve error message when closing a connection

fixes #228
This commit is contained in:
Lucas Clemente
2016-07-29 12:04:04 +02:00
parent 2d48210fa0
commit 7ab2eb1b93
3 changed files with 20 additions and 7 deletions

View File

@@ -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
}
}

View File

@@ -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

View File

@@ -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() {