mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-29 11:12:04 +01:00
Fix unblock mutex
- if `receivedEvent.ID` not match `event.ID`, may trigger an error `fatal error: sync: unlock of unlocked mutex`. - if context cancled, it does not needs mutex.
This commit is contained in:
parent
4aee139f6c
commit
ab2db2dfc5
3
relay.go
3
relay.go
@ -234,7 +234,6 @@ func (r *Relay) Publish(ctx context.Context, event Event) Status {
|
||||
}
|
||||
|
||||
sub := r.Subscribe(ctx, Filters{Filter{IDs: []string{event.ID}}})
|
||||
defer mu.Unlock()
|
||||
for {
|
||||
select {
|
||||
case receivedEvent := <-sub.Events:
|
||||
@ -242,6 +241,7 @@ func (r *Relay) Publish(ctx context.Context, event Event) Status {
|
||||
// we got a success, so update our status and proceed to return
|
||||
mu.Lock()
|
||||
status = PublishStatusSucceeded
|
||||
mu.Unlock()
|
||||
return status
|
||||
}
|
||||
case <-ctx.Done():
|
||||
@ -250,7 +250,6 @@ func (r *Relay) Publish(ctx context.Context, event Event) Status {
|
||||
// e.g. if this happens because of the timeout then status will probably be "failed"
|
||||
// but if it happens because okCallback was called then it might be "succeeded"
|
||||
// do not return if okCallback is in process
|
||||
mu.Lock()
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user