From b6aad5d1dbdd2e89d9bafd6d902a18a94bc6d8b7 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sun, 12 Apr 2026 22:25:14 -0400 Subject: [PATCH] crypto/tls: add QUICErrorEvent Add a new QUICEvent type for reporting errors. This provides a way to report errors that don't occur as a result of QUICConn.Start, QUICConn.HandleData, or QUICConn.SendSessionTicket. Fixes #75108 Change-Id: I941371a21f26b940e75287a66d7e0211fc0baab1 Reviewed-on: https://go-review.googlesource.com/c/go/+/719040 Auto-Submit: Damien Neil LUCI-TryBot-Result: Go LUCI Reviewed-by: Roland Shoemaker --- quic.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/quic.go b/quic.go index 286afe8..3f8d6a7 100644 --- a/quic.go +++ b/quic.go @@ -117,6 +117,11 @@ const ( // The application may modify the [SessionState] before storing it. // This event only occurs on client connections. QUICStoreSession + + // QUICErrorEvent indicates that a fatal error has occurred. + // The handshake cannot proceed and the connection must be closed. + // QUICEvent.Err is set. + QUICErrorEvent ) // A QUICEvent is an event occurring on a QUIC connection. @@ -138,6 +143,10 @@ type QUICEvent struct { // Set for QUICResumeSession and QUICStoreSession. SessionState *SessionState + + // Set for QUICErrorEvent. + // The error will wrap AlertError. + Err error } type quicState struct { @@ -157,6 +166,7 @@ type quicState struct { cancel context.CancelFunc waitingForDrain bool + errorReturned bool // readbuf is shared between HandleData and the handshake goroutine. // HandshakeCryptoData passes ownership to the handshake goroutine by @@ -230,6 +240,15 @@ func (q *QUICConn) NextEvent() QUICEvent { <-qs.signalc <-qs.blockedc } + if err := q.conn.handshakeErr; err != nil { + if qs.errorReturned { + return QUICEvent{Kind: QUICNoEvent} + } + qs.errorReturned = true + qs.events = nil + qs.nextEvent = 0 + return QUICEvent{Kind: QUICErrorEvent, Err: q.conn.handshakeErr} + } if qs.nextEvent >= len(qs.events) { qs.events = qs.events[:0] qs.nextEvent = 0