Skip to content

Commit

Permalink
proxy: quic errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Jun 27, 2023
1 parent f29f71d commit cc6acb4
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions proxy/server_quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (p *Proxy) quicPacketLoop(l *quic.EarlyListener, requestGoroutinesSema sema
for {
conn, err := l.Accept(context.Background())
if err != nil {
if isQUICNonCrit(err) {
if isQUICErrorForDebugLog(err) {
log.Debug("accepting quic conn: closed or timed out: %s", err)
} else {
log.Error("accepting quic conn: %s", err)
Expand Down Expand Up @@ -117,7 +117,7 @@ func (p *Proxy) handleQUICConnection(conn quic.Connection, requestGoroutinesSema
// bidirectional stream.
stream, err := conn.AcceptStream(context.Background())
if err != nil {
if isQUICNonCrit(err) {
if isQUICErrorForDebugLog(err) {
log.Debug("accepting quic stream: closed or timed out: %s", err)
} else {
log.Error("accepting quic stream: %s", err)
Expand Down Expand Up @@ -309,32 +309,28 @@ func logShortQUICRead(err error) {
return
}

if isQUICNonCrit(err) {
if isQUICErrorForDebugLog(err) {
log.Debug("reading from quic stream: closed or timeout: %s", err)
} else {
log.Error("reading from quic stream: %s", err)
}
}

const (
// QUICCodeNoError is returned when the QUIC connection was gracefully
// closed and there is no error to signal.
QUICCodeNoError = quic.ApplicationErrorCode(quic.NoError)
// qCodeNoError is returned when the QUIC connection was gracefully closed
// and there is no error to signal.
qCodeNoError = quic.ApplicationErrorCode(quic.NoError)

// QUICCodeApplicationErrorError is used for Initial and Handshake packets.
// qCodeApplicationErrorError is used for Initial and Handshake packets.
// This error is considered as non-critical and will not be logged as error.
QUICCodeApplicationErrorError = quic.ApplicationErrorCode(quic.ApplicationErrorErrorCode)
qCodeApplicationErrorError = quic.ApplicationErrorCode(quic.ApplicationErrorErrorCode)
)

// isQUICNonCrit returns true if err is a non-critical error, most probably
// related to the current QUIC implementation.
// isQUICErrorForDebugLog returns true if err is a non-critical error, most probably
// related to the current QUIC implementation. err must not be nil.
//
// TODO(ameshkov): re-test when updating quic-go.
func isQUICNonCrit(err error) (ok bool) {
if err == nil {
return false
}

func isQUICErrorForDebugLog(err error) (ok bool) {
if errors.Is(err, quic.ErrServerClosed) {
// This error is returned when the QUIC listener was closed by us. This
// is an expected error, we don't need the detailed logs here.
Expand All @@ -343,8 +339,7 @@ func isQUICNonCrit(err error) (ok bool) {

var qAppErr *quic.ApplicationError
if errors.As(err, &qAppErr) &&
(qAppErr.ErrorCode == QUICCodeNoError ||
qAppErr.ErrorCode == QUICCodeApplicationErrorError) {
(qAppErr.ErrorCode == qCodeNoError || qAppErr.ErrorCode == qCodeApplicationErrorError) {
// No need to have detailed logs for these error codes either.
//
// TODO(a.garipov): Consider adding other error codes.
Expand Down

0 comments on commit cc6acb4

Please sign in to comment.