From d2e85b5806bf24c182a243c40732166960bf58f5 Mon Sep 17 00:00:00 2001 From: Ian Denhardt Date: Mon, 13 Feb 2023 19:32:28 -0500 Subject: [PATCH] Hold lock while accessing c.stream.err For some reason I'd been under the impression that startCall acquired this and released it in finish(), but that's not the case. --- capability.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/capability.go b/capability.go index fb5b9d18..1708ce4c 100644 --- a/capability.go +++ b/capability.go @@ -327,8 +327,13 @@ func (c Client) SendCall(ctx context.Context, s Send) (*Answer, ReleaseFunc) { return ErrorAnswer(s.Method, errors.New("call on null client")), func() {} } - if c.stream.err != nil { - return ErrorAnswer(s.Method, exc.WrapError("stream error", c.stream.err)), func() {} + var err error + syncutil.With(&c.mu, func() { + err = c.stream.err + }) + + if err != nil { + return ErrorAnswer(s.Method, exc.WrapError("stream error", err)), func() {} } limiter := c.GetFlowLimiter()