Skip to content

Commit

Permalink
fix: possible race condition leading to rare panic in GetOperationEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Jul 15, 2024
1 parent d93068a commit f250adf
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions internal/api/backresthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,17 @@ func (s *BackrestHandler) GetOperationEvents(ctx context.Context, req *connect.R
s.oplog.Subscribe(&callback)
defer s.oplog.Unsubscribe(&callback)

go func() {
for {
select {
case <-ctx.Done():
return
case event := <-events:
if err := resp.Send(event); err != nil {
select {
case errChan <- errors.New("failed to send event"):
default:
}
}
for {
select {
case err := <-errChan:
return err
case <-ctx.Done():
return nil
case event := <-events:
if err := resp.Send(event); err != nil {
return err
}
}
}()

select {
case err := <-errChan:
return err
case <-ctx.Done():
return nil
}
}

Expand Down

0 comments on commit f250adf

Please sign in to comment.