Skip to content

Commit

Permalink
fix stream cancellation after 0-RTT rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
espadolini committed Oct 18, 2024
1 parent e9ea132 commit 027286f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/proxy/peer/quicclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ func (c *quicClientConn) dial(nodeID string, src net.Addr, dst net.Addr, tunnelT
log.DebugContext(conn.Context(), "full handshake completed after 0-RTT rejection")
respBuf, stream, err = quicSendUnary(deadline, sizedReqBuf, conn)
if err != nil {
log.DebugContext(conn.Context(),
"failed to exchange dial request after 0-RTT rejection and handshake",
"error", err,
)
return nil, trace.Wrap(err)
}
}
Expand All @@ -292,6 +296,10 @@ func (c *quicClientConn) dial(nodeID string, src net.Addr, dst net.Addr, tunnelT
select {
case <-earlyConn.HandshakeComplete():
case <-earlyConn.Context().Done():
log.DebugContext(conn.Context(),
"failed to complete handshake after exchanging 0-RTT dial request",
"error", err,
)
return nil, trace.Wrap(context.Cause(earlyConn.Context()))
}
}
Expand Down Expand Up @@ -332,6 +340,14 @@ func quicSendUnary(deadline time.Time, sizedReqBuf []byte, conn quic.Connection)
if err == nil {
return
}
if errors.Is(err, quic.Err0RTTRejected) {
// because of a bug (or maybe an API design flaw?), resetting a
// stream after receiving a [quic.Err0RTTRejected] can affect new
// streams in the post-handshake connection; thankfully, since the
// old connection state is guaranteed to be gone after a 0-RTT
// rejection, there's no reason to explicitly cancel the stream
return
}
stream.CancelRead(0)
stream.CancelWrite(0)
}()
Expand Down

0 comments on commit 027286f

Please sign in to comment.