Skip to content

Commit 9c6fbfc

Browse files
committed
TUN-7471: Fixes cloudflared not closing the quic stream on unregister UDP session
This code was leaking streams because it wasn't closing the quic stream after unregistering from the edge.
1 parent 925ec10 commit 9c6fbfc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

connection/quic.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func (q *QUICConnection) serveUDPSession(session *datagramsession.Session, close
357357
// closeUDPSession first unregisters the session from session manager, then it tries to unregister from edge
358358
func (q *QUICConnection) closeUDPSession(ctx context.Context, sessionID uuid.UUID, message string) {
359359
q.sessionManager.UnregisterSession(ctx, sessionID, message, false)
360-
stream, err := q.session.OpenStream()
360+
quicStream, err := q.session.OpenStream()
361361
if err != nil {
362362
// Log this at debug because this is not an error if session was closed due to lost connection
363363
// with edge
@@ -367,6 +367,9 @@ func (q *QUICConnection) closeUDPSession(ctx context.Context, sessionID uuid.UUI
367367
Msgf("Failed to open quic stream to unregister udp session with edge")
368368
return
369369
}
370+
371+
stream := quicpogs.NewSafeStreamCloser(quicStream)
372+
defer stream.Close()
370373
rpcClientStream, err := quicpogs.NewRPCClientStream(ctx, stream, q.logger)
371374
if err != nil {
372375
// Log this at debug because this is not an error if session was closed due to lost connection
@@ -375,6 +378,8 @@ func (q *QUICConnection) closeUDPSession(ctx context.Context, sessionID uuid.UUI
375378
Msgf("Failed to open rpc stream to unregister udp session with edge")
376379
return
377380
}
381+
defer rpcClientStream.Close()
382+
378383
if err := rpcClientStream.UnregisterUdpSession(ctx, sessionID, message); err != nil {
379384
q.logger.Err(err).Str("sessionID", sessionID.String()).
380385
Msgf("Failed to unregister udp session with edge")

0 commit comments

Comments
 (0)