From 20d65d4a761d9cb102286879c7fbb8e94d5d3f8e Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 6 Nov 2023 00:36:24 +0900 Subject: [PATCH] fix race condition in Close --- relay.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/relay.go b/relay.go index 11aabc4..ea69eeb 100644 --- a/relay.go +++ b/relay.go @@ -39,6 +39,8 @@ func (s Status) String() string { } type Relay struct { + mu sync.Mutex + URL string RequestHeader http.Header // e.g. for origin header @@ -553,6 +555,9 @@ func (r *Relay) Count(ctx context.Context, filters Filters, opts ...Subscription } func (r *Relay) Close() error { + r.mu.Lock() + defer r.mu.Unlock() + if r.connectionContextCancel == nil { return fmt.Errorf("relay not connected") }