Skip to content

Commit 58eb564

Browse files
authored
remove panic, and revert connserver from using non-blocking drainchannel safe (#2049)
1 parent 49bc6d3 commit 58eb564

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

cmd/wsh/cmd/wshcmd-connserver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/wshfs"
2222
"github.com/wavetermdev/waveterm/pkg/util/packetparser"
2323
"github.com/wavetermdev/waveterm/pkg/util/sigutil"
24-
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
2524
"github.com/wavetermdev/waveterm/pkg/wavebase"
2625
"github.com/wavetermdev/waveterm/pkg/wshrpc"
2726
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
@@ -163,7 +162,9 @@ func serverRunRouter(jwtToken string) error {
163162
// just ignore and drain the rawCh (stdin)
164163
// when stdin is closed, shutdown
165164
defer wshutil.DoShutdown("", 0, true)
166-
utilfn.DrainChannelSafe(rawCh, "serverRunRouter:stdin")
165+
for range rawCh {
166+
// ignore
167+
}
167168
}()
168169
go func() {
169170
for msg := range termProxy.FromRemoteCh {

pkg/util/utilfn/utilfn.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,15 +1057,16 @@ func GracefulClose(closer io.Closer, debugName, closerName string) bool {
10571057
}
10581058

10591059
// DrainChannelSafe will drain a channel until it is empty or until a timeout is reached.
1060-
// WARNING: This function will panic if the channel is not drained within the timeout.
10611060
func DrainChannelSafe[T any](ch <-chan T, debugName string) {
10621061
drainTimeoutCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
10631062
go func() {
10641063
defer cancel()
1064+
outer:
10651065
for {
10661066
select {
10671067
case <-drainTimeoutCtx.Done():
1068-
panic(debugName + ": timeout draining channel")
1068+
log.Printf("[error] timeout draining channel: %s\n", debugName)
1069+
break outer
10691070
case _, ok := <-ch:
10701071
if !ok {
10711072
return

0 commit comments

Comments
 (0)