viaduct: closing a connection can panic with "send on closed channel", and QUIC readers are never released on teardown
What happened:
Two defects in the viaduct connection teardown path, found while following up on #6966 and #6967.
MessageFifo.Closecloses the channel thatMessageFifo.Putsends on.Putruns on a connection's read loop (WSConnection.handleMessage/QuicConnection.handleMessage) andCloseruns on the teardown path, so when a message arrives while a connection is being closed the two overlap and the process dies withpanic: send on closed channel. On the edge this is reachable on the WebSocket transport:WSConnection.Closecloses the fifo, and EdgeHub callsUnIniton a live connection during certificate rotation (enabled by default) and on module stop.QuicConnection.Closedestroys the streams and closes the session but leaves the message fifo open.ReadMessageparks on that fifo rather than on the session, so the reader of a torn-down QUIC connection never returns. In EdgeHub that reader isrouteToEdge: after the reconnect loop callsUnInitand connects again, the old goroutine stays blocked on the previous connection, leaking one goroutine per reconnect. The per-connection stop channel added in #6967 does not release it, because the goroutine is blocked insideReceiverather than at the top of its loop.
What you expected to happen:
Closing a connection releases its readers and never panics, regardless of whether a message is being delivered at that moment.
How to reproduce it (as minimally and precisely as possible):
Both reproduce with Go tests against master (ceb5eacd1), no cluster needed.
Panic: run
MessageFifo.PutandMessageFifo.Closeconcurrently on the same fifo; the first iteration panics withsend on closed channel. On the real transport path, create aWSConnectionwithAutoRoute: false(the edge setting), starthandleMessage, keep sending messages from the peer, and callClose; the panic stack isMessageFifo.Putcalled fromWSConnection.handleMessage.Leak: connect an edge
QuicClientto a viaduct QUIC server, start a goroutine inReceive, then callUnInit.Receivenever returns. Repeated three times, three goroutines stay parked inMessageFifo.Get. The same steps on the WebSocket client release all three, becauseWSConnection.Closecloses the fifo.
Anything else we need to know?:
- The two are related: closing the fifo from
QuicConnection.Closeis the fix for the leak, but it is only safe onceClosecannot racePut, so both need to land together. - QUIC does not have the read-deadline defect fixed for WebSocket in #6966. quic-go's own session idle timeout surfaces a half-open path (measured at 30s with the default configuration), so that part of #6965 does not apply to QUIC; the leak above is what affects QUIC users.
- Fix in preparation, will be linked here.
Environment:
Kubernetes version (use
kubectl version): not applicable, reproduced with unit testsKubeEdge version(e.g.
cloudcore --versionandedgecore --version): master atceb5eacd1- Cloud nodes Environment:
- Hardware configuration (e.g.
lscpu): not applicable - OS (e.g.
cat /etc/os-release): not applicable - Kernel (e.g.
uname -a): not applicable - Go version (e.g.
go version): go 1.25.14 (go.mod) - Others: reproduced with
go teston macOS arm64 and in the repository's Linux CI
- Hardware configuration (e.g.
- Edge nodes Environment:
- edgecore version (e.g.
edgecore --version): master atceb5eacd1 - Hardware configuration (e.g.
lscpu): not applicable - OS (e.g.
cat /etc/os-release): not applicable - Kernel (e.g.
uname -a): not applicable - Go version (e.g.
go version): go 1.25.14 (go.mod) - Others: affected code paths are
pkg/viaduct/pkg/fifo/msgfifo.go,pkg/viaduct/pkg/conn/ws.go,pkg/viaduct/pkg/conn/quic.go
- edgecore version (e.g.
Source: kubeedge/kubeedge