Skip to content

Commit

Permalink
Server.handleCall: Run methods when the ctx is already canceled
Browse files Browse the repository at this point in the history
...and let the method implementation check the context itself.

This solves an occasional hang (observed in capnproto#318) in TestRecvCancel,
which involves a method implementation that waits for its context to be
canceled and then closes a channel. Without this patch, if the context
is cancelled early enough for handleCall to see it, it won't run the
method at all, and so the channel will never be closed, causing the test
to hang on a receive on that channel.
  • Loading branch information
zenhack committed Oct 14, 2022
1 parent f561d79 commit e398e1c
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ func (srv *Server) handleCalls(ctx context.Context) {
func (srv *Server) handleCall(ctx context.Context, c *Call) {
defer srv.wg.Done()

err := ctx.Err()
if err == nil {
err = c.method.Impl(ctx, c)
}
err := c.method.Impl(ctx, c)

c.recv.ReleaseArgs()
if err == nil {
Expand Down

0 comments on commit e398e1c

Please sign in to comment.