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.
This commit is contained in:
parent
925ec100d6
commit
9c6fbfca18
|
@ -357,7 +357,7 @@ func (q *QUICConnection) serveUDPSession(session *datagramsession.Session, close
|
||||||
// closeUDPSession first unregisters the session from session manager, then it tries to unregister from edge
|
// closeUDPSession first unregisters the session from session manager, then it tries to unregister from edge
|
||||||
func (q *QUICConnection) closeUDPSession(ctx context.Context, sessionID uuid.UUID, message string) {
|
func (q *QUICConnection) closeUDPSession(ctx context.Context, sessionID uuid.UUID, message string) {
|
||||||
q.sessionManager.UnregisterSession(ctx, sessionID, message, false)
|
q.sessionManager.UnregisterSession(ctx, sessionID, message, false)
|
||||||
stream, err := q.session.OpenStream()
|
quicStream, err := q.session.OpenStream()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Log this at debug because this is not an error if session was closed due to lost connection
|
// Log this at debug because this is not an error if session was closed due to lost connection
|
||||||
// with edge
|
// with edge
|
||||||
|
@ -367,6 +367,9 @@ func (q *QUICConnection) closeUDPSession(ctx context.Context, sessionID uuid.UUI
|
||||||
Msgf("Failed to open quic stream to unregister udp session with edge")
|
Msgf("Failed to open quic stream to unregister udp session with edge")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stream := quicpogs.NewSafeStreamCloser(quicStream)
|
||||||
|
defer stream.Close()
|
||||||
rpcClientStream, err := quicpogs.NewRPCClientStream(ctx, stream, q.logger)
|
rpcClientStream, err := quicpogs.NewRPCClientStream(ctx, stream, q.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Log this at debug because this is not an error if session was closed due to lost connection
|
// 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
|
||||||
Msgf("Failed to open rpc stream to unregister udp session with edge")
|
Msgf("Failed to open rpc stream to unregister udp session with edge")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer rpcClientStream.Close()
|
||||||
|
|
||||||
if err := rpcClientStream.UnregisterUdpSession(ctx, sessionID, message); err != nil {
|
if err := rpcClientStream.UnregisterUdpSession(ctx, sessionID, message); err != nil {
|
||||||
q.logger.Err(err).Str("sessionID", sessionID.String()).
|
q.logger.Err(err).Str("sessionID", sessionID.String()).
|
||||||
Msgf("Failed to unregister udp session with edge")
|
Msgf("Failed to unregister udp session with edge")
|
||||||
|
|
Loading…
Reference in New Issue