From c1c494048489dd42ad7c1af5503d8ccc61b627d2 Mon Sep 17 00:00:00 2001 From: patrickhuie19 Date: Thu, 7 Dec 2023 21:05:58 -0500 Subject: [PATCH] fixing logical race when Close is called before Invoke --- client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 3d5027d..7174f05 100644 --- a/client.go +++ b/client.go @@ -369,8 +369,12 @@ func (cc *ClientConn) Close() { // Invoke sends the RPC request on the wire and returns after response is // received. func (cc *ClientConn) Invoke(ctx context.Context, method string, args interface{}, reply interface{}) error { - // Ensure the connection state is ready + if cc.addrConn == nil { + // Close() has been called + return errors.New("client Close() called") + } + // Ensure the connection state is ready cc.mu.RLock() cc.addrConn.mu.RLock() state := cc.addrConn.state