#7328·kubeedge

viaduct: closing a connection can panic with "send on closed channel", and QUIC readers are never released on teardown

Author: ryoheimorimotoCreated Sep 24, 2026Updated Sep 24, 2026
Labelskind/bug

What happened:

Two defects in the viaduct connection teardown path, found while following up on #6966 and #6967.

  1. MessageFifo.Close closes the channel that MessageFifo.Put sends on. Put runs on a connection's read loop (WSConnection.handleMessage / QuicConnection.handleMessage) and Close runs on the teardown path, so when a message arrives while a connection is being closed the two overlap and the process dies with panic: send on closed channel. On the edge this is reachable on the WebSocket transport: WSConnection.Close closes the fifo, and EdgeHub calls UnInit on a live connection during certificate rotation (enabled by default) and on module stop.

  2. QuicConnection.Close destroys the streams and closes the session but leaves the message fifo open. ReadMessage parks on that fifo rather than on the session, so the reader of a torn-down QUIC connection never returns. In EdgeHub that reader is routeToEdge: after the reconnect loop calls UnInit and 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 inside Receive rather 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.

  1. Panic: run MessageFifo.Put and MessageFifo.Close concurrently on the same fifo; the first iteration panics with send on closed channel. On the real transport path, create a WSConnection with AutoRoute: false (the edge setting), start handleMessage, keep sending messages from the peer, and call Close; the panic stack is MessageFifo.Put called from WSConnection.handleMessage.

  2. Leak: connect an edge QuicClient to a viaduct QUIC server, start a goroutine in Receive, then call UnInit. Receive never returns. Repeated three times, three goroutines stay parked in MessageFifo.Get. The same steps on the WebSocket client release all three, because WSConnection.Close closes the fifo.

Anything else we need to know?:

  • The two are related: closing the fifo from QuicConnection.Close is the fix for the leak, but it is only safe once Close cannot race Put, 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 tests

  • KubeEdge version(e.g. cloudcore --version and edgecore --version): master at ceb5eacd1

  • 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 test on macOS arm64 and in the repository's Linux CI
  • Edge nodes Environment:
    • edgecore version (e.g. edgecore --version): master at ceb5eacd1
    • 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