client close nicely
This commit is contained in:
parent
2005fbcf44
commit
3a5af241e7
@ -49,6 +49,7 @@ type client struct {
|
||||
wantResponseId uint64
|
||||
wantResponse chan []byte
|
||||
lock sync.Mutex
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func newClient(conn *websocket.Conn, a *Agent) *client {
|
||||
@ -142,9 +143,12 @@ func (c *client) writePump() {
|
||||
}
|
||||
|
||||
func (c *client) Close() {
|
||||
c.fnCancel()
|
||||
c.agent.removeClient(c)
|
||||
c.conn.Close()
|
||||
once.Do(func(){
|
||||
c.fnCancel()
|
||||
c.agent.removeClient(c)
|
||||
c.conn.Close()
|
||||
log.Info("client close", "remote", c.conn.RemoteAddr().String(), "connected", c.agent.clients.Size())
|
||||
})
|
||||
}
|
||||
|
||||
func (c *client) WriteJson(data interface{}, block bool) error {
|
||||
|
@ -47,8 +47,8 @@ func (task *Task) SendExecFail(errMsg string) {
|
||||
|
||||
func (task *Task) do() {
|
||||
defer func() {
|
||||
<-task.pool.sem
|
||||
task.pool.remove(task.client)
|
||||
<-task.pool.sem
|
||||
if err := recover(); err != nil {
|
||||
log.Error("[Task] do panic", "err", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user