From e398e1c3aa7fd3f52ea725acfad74e664f69ac1e Mon Sep 17 00:00:00 2001 From: Ian Denhardt Date: Fri, 14 Oct 2022 00:09:54 -0400 Subject: [PATCH] Server.handleCall: Run methods when the ctx is already canceled ...and let the method implementation check the context itself. This solves an occasional hang (observed in #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. --- server/server.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/server.go b/server/server.go index 3f8646c4..6388affd 100644 --- a/server/server.go +++ b/server/server.go @@ -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 {