fix race condition in Close
This commit is contained in:
committed by
fiatjaf_
parent
29646d8bec
commit
20d65d4a76
5
relay.go
5
relay.go
@@ -39,6 +39,8 @@ func (s Status) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Relay struct {
|
type Relay struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
|
||||||
URL string
|
URL string
|
||||||
RequestHeader http.Header // e.g. for origin header
|
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 {
|
func (r *Relay) Close() error {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
if r.connectionContextCancel == nil {
|
if r.connectionContextCancel == nil {
|
||||||
return fmt.Errorf("relay not connected")
|
return fmt.Errorf("relay not connected")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user