diff --git a/cmd/dashboard/controller/fm.go b/cmd/dashboard/controller/fm.go index bdcd7a2..9bd14b3 100644 --- a/cmd/dashboard/controller/fm.go +++ b/cmd/dashboard/controller/fm.go @@ -95,5 +95,9 @@ func fmStream(c *gin.Context) (any, error) { return nil, newWsError("%v", err) } - return nil, newWsError("%v", rpc.NezhaHandlerSingleton.StartStream(streamId, time.Second*10)) + if err = rpc.NezhaHandlerSingleton.StartStream(streamId, time.Second*10); err != nil { + return nil, newWsError("%v", err) + } + + return nil, newWsError("") } diff --git a/cmd/dashboard/controller/terminal.go b/cmd/dashboard/controller/terminal.go index 67466ba..2b54417 100644 --- a/cmd/dashboard/controller/terminal.go +++ b/cmd/dashboard/controller/terminal.go @@ -95,5 +95,9 @@ func terminalStream(c *gin.Context) (any, error) { return nil, newWsError("%v", err) } - return nil, newWsError("%v", rpc.NezhaHandlerSingleton.StartStream(streamId, time.Second*10)) + if err = rpc.NezhaHandlerSingleton.StartStream(streamId, time.Second*10); err != nil { + return nil, newWsError("%v", err) + } + + return nil, newWsError("") } diff --git a/service/rpc/io_stream.go b/service/rpc/io_stream.go index 2270672..313083b 100644 --- a/service/rpc/io_stream.go +++ b/service/rpc/io_stream.go @@ -15,6 +15,8 @@ type ioStreamContext struct { agentIo io.ReadWriteCloser userIoConnectCh chan struct{} agentIoConnectCh chan struct{} + userIoChOnce sync.Once + agentIoChOnce sync.Once } type bp struct { @@ -74,7 +76,9 @@ func (s *NezhaHandler) UserConnected(streamId string, userIo io.ReadWriteCloser) } stream.userIo = userIo - close(stream.userIoConnectCh) + stream.userIoChOnce.Do(func() { + close(stream.userIoConnectCh) + }) return nil } @@ -86,7 +90,9 @@ func (s *NezhaHandler) AgentConnected(streamId string, agentIo io.ReadWriteClose } stream.agentIo = agentIo - close(stream.agentIoConnectCh) + stream.agentIoChOnce.Do(func() { + close(stream.agentIoConnectCh) + }) return nil }