Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/wsh/cmd/wshcmd-connserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/util/utilfn/utilfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading