Skip to content

Commit

Permalink
fix race condition in Close
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn authored and fiatjaf committed Nov 5, 2023
1 parent 29646d8 commit 20d65d4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 20d65d4

Please sign in to comment.