Skip to content

Commit

Permalink
defer wg.Done so it's called even if there's a panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Asim Aslam committed Jun 12, 2017
1 parent 32b7ebc commit 3812cbb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions server/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3812cbb

Please sign in to comment.