From bd90183133e582d9277bac2b66976b28d666d94c Mon Sep 17 00:00:00 2001 From: sawka Date: Sat, 8 Mar 2025 12:03:24 -0800 Subject: [PATCH] remote panic, and revert connserver from using non-blocking drainchannel safe --- cmd/wsh/cmd/wshcmd-connserver.go | 5 +++-- pkg/util/utilfn/utilfn.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/wsh/cmd/wshcmd-connserver.go b/cmd/wsh/cmd/wshcmd-connserver.go index d9c7a8bc07..678ea77cc5 100644 --- a/cmd/wsh/cmd/wshcmd-connserver.go +++ b/cmd/wsh/cmd/wshcmd-connserver.go @@ -21,7 +21,6 @@ import ( "github.com/wavetermdev/waveterm/pkg/remote/fileshare/wshfs" "github.com/wavetermdev/waveterm/pkg/util/packetparser" "github.com/wavetermdev/waveterm/pkg/util/sigutil" - "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/wavebase" "github.com/wavetermdev/waveterm/pkg/wshrpc" "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" @@ -163,7 +162,9 @@ func serverRunRouter(jwtToken string) error { // just ignore and drain the rawCh (stdin) // when stdin is closed, shutdown defer wshutil.DoShutdown("", 0, true) - utilfn.DrainChannelSafe(rawCh, "serverRunRouter:stdin") + for range rawCh { + // ignore + } }() go func() { for msg := range termProxy.FromRemoteCh { diff --git a/pkg/util/utilfn/utilfn.go b/pkg/util/utilfn/utilfn.go index f5765e0078..f7d180e596 100644 --- a/pkg/util/utilfn/utilfn.go +++ b/pkg/util/utilfn/utilfn.go @@ -1057,15 +1057,16 @@ func GracefulClose(closer io.Closer, debugName, closerName string) bool { } // DrainChannelSafe will drain a channel until it is empty or until a timeout is reached. -// WARNING: This function will panic if the channel is not drained within the timeout. func DrainChannelSafe[T any](ch <-chan T, debugName string) { drainTimeoutCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) go func() { defer cancel() + outer: for { select { case <-drainTimeoutCtx.Done(): - panic(debugName + ": timeout draining channel") + log.Printf("[error] timeout draining channel: %s\n", debugName) + break outer case _, ok := <-ch: if !ok { return