Skip to content

Commit 4016334

Browse files
committed
TUN-6642: Fix unexpected close of quic stream triggered by upstream origin close
This commit guarantees that stream is only closed once the are finished handling the stream. Without it, we were seeing closes being triggered by the code that proxies to the origin, which was resulting in failures to actually send downstream the status code of the proxy request to the eyeball. This was then subsequently triggering unexpected retries to cloudflared in situations such as cloudflared being unable to reach the origin.
1 parent d4d9a43 commit 4016334

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

connection/quic.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ func (q *QUICConnection) runStream(quicStream quic.Stream) {
147147
stream := quicpogs.NewSafeStreamCloser(quicStream)
148148
defer stream.Close()
149149

150-
if err := q.handleStream(ctx, stream); err != nil {
150+
// we are going to fuse readers/writers from stream <- cloudflared -> origin, and we want to guarantee that
151+
// code executed in the code path of handleStream don't trigger an earlier close to the downstream stream.
152+
// So, we wrap the stream with a no-op closer and only this method can actually close the stream.
153+
noCloseStream := &nopCloserReadWriter{stream}
154+
if err := q.handleStream(ctx, noCloseStream); err != nil {
151155
q.logger.Err(err).Msg("Failed to handle QUIC stream")
152156
}
153157
}
@@ -395,3 +399,11 @@ func isTransferEncodingChunked(req *http.Request) bool {
395399
// separated value as well.
396400
return strings.Contains(strings.ToLower(transferEncodingVal), "chunked")
397401
}
402+
403+
type nopCloserReadWriter struct {
404+
io.ReadWriteCloser
405+
}
406+
407+
func (n *nopCloserReadWriter) Close() error {
408+
return nil
409+
}

0 commit comments

Comments
 (0)