Skip to content

Commit

Permalink
Fixed Client.Close logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
林志宇 committed Jun 15, 2019
1 parent b648d5d commit 149844b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/dmsg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,7 @@ func (c *ClientConn) Serve(ctx context.Context, accept chan<- *Transport) (err e
log := c.log.WithField("remoteServer", c.remoteSrv)
log.WithField("connCount", incrementServeCount()).Infoln("ServingConn")
defer func() {
log.WithError(err).WithField("connCount", decrementServeCount()).Infoln("ClosingConn")
c.mx.Lock()
for _, tp := range c.tps {
if tp != nil {
go tp.Close() //nolint:errcheck
}
}
_ = c.Conn.Close() //nolint:errcheck
c.mx.Unlock()
log.WithError(err).WithField("connCount", decrementServeCount()).Infoln("ConnectionClosed")
c.wg.Done()
}()

Expand Down Expand Up @@ -255,8 +247,17 @@ func (c *ClientConn) Close() error {
closed = true
c.log.WithField("remoteServer", c.remoteSrv).Infoln("ClosingConnection")
close(c.done)
c.mx.Lock()
for _, tp := range c.tps {
if tp != nil {
go tp.Close() //nolint:errcheck
}
}
_ = c.Conn.Close() //nolint:errcheck
c.mx.Unlock()
c.wg.Wait()
})
c.wg.Wait()

if !closed {
return ErrClientClosed
}
Expand Down

0 comments on commit 149844b

Please sign in to comment.