fix: only close user/agentIo connect channel once (#21)
This commit is contained in:
		
							parent
							
								
									45f11483ec
								
							
						
					
					
						commit
						07989705d2
					
				@ -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("")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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("")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
	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
 | 
			
		||||
	stream.agentIoChOnce.Do(func() {
 | 
			
		||||
		close(stream.agentIoConnectCh)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user