mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-12 09:51:51 +02: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}}})
|
sub := r.Subscribe(ctx, Filters{Filter{IDs: []string{event.ID}}})
|
||||||
defer mu.Unlock()
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case receivedEvent := <-sub.Events:
|
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
|
// we got a success, so update our status and proceed to return
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
status = PublishStatusSucceeded
|
status = PublishStatusSucceeded
|
||||||
|
mu.Unlock()
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
case <-ctx.Done():
|
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"
|
// 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"
|
// but if it happens because okCallback was called then it might be "succeeded"
|
||||||
// do not return if okCallback is in process
|
// do not return if okCallback is in process
|
||||||
mu.Lock()
|
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user