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