defer wg.Done so it's called even if there's a panic

This commit is contained in:
Asim Aslam 2017-06-12 14:18:59 +01:00
parent 32b7ebcfbc
commit 3812cbbcb6
2 changed files with 2 additions and 5 deletions

View File

@ -104,16 +104,13 @@ func (s *rpcServer) accept(sock transport.Socket) {
// add to wait group
s.wg.Add(1)
defer s.wg.Done()
// TODO: needs better error handling
if err := s.rpc.serveRequest(ctx, codec, ct); err != nil {
log.Logf("Unexpected error serving request, closing socket: %v", err)
s.wg.Done()
return
}
// finish request
s.wg.Done()
}
}

View File

@ -228,12 +228,12 @@ func (s *rpcServer) createSubHandler(sb *subscriber, opts Options) broker.Handle
s.wg.Add(1)
go func() {
defer s.wg.Done()
fn(ctx, &rpcPublication{
topic: sb.topic,
contentType: ct,
message: req.Interface(),
})
s.wg.Done()
}()
}
return nil