Skip to content

Commit

Permalink
hacky fix for racecondition
Browse files Browse the repository at this point in the history
  • Loading branch information
Inveracity committed Jul 22, 2023
1 parent c0dd1fe commit 86d341b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions relay/internal/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package queue
import (
"context"
"log"
"time"

"github.com/nats-io/nats.go"
)
Expand Down Expand Up @@ -48,6 +49,7 @@ func (q *Queue) Subscribe(ctx context.Context, channel string) error {
// either the context is cancelled or an error was caught on the error channel
// Currently unsure why.
case <-ctx.Done():
time.Sleep(1 + time.Second) // TODO: There's a race condition when a client disconnects and the server wants to broadcast a message.
sub.Unsubscribe()

Check failure on line 53 in relay/internal/queue/queue.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `sub.Unsubscribe` is not checked (errcheck)
log.Printf("NATS %s: unsubscribing and closing stream", q.streamid)
q.Close()
Expand Down

0 comments on commit 86d341b

Please sign in to comment.