Skip to content

Commit

Permalink
docs: add comments to clarify that WaitNotices releases the state lock (
Browse files Browse the repository at this point in the history
  • Loading branch information
benhoyt authored Mar 5, 2024
1 parent 95b73bb commit 9986cdf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions internals/daemon/api_notices.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func v1GetNotices(c *Command, r *http.Request, _ *UserState) Response {
ctx, cancel := context.WithTimeout(r.Context(), timeout)
defer cancel()

// WaitNotices releases the state lock while waiting.
notices, err = st.WaitNotices(ctx, filter)
if errors.Is(err, context.Canceled) {
return BadRequest("request canceled")
Expand Down
5 changes: 4 additions & 1 deletion internals/overlord/state/notices.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ func (s *State) unflattenNotices(flat []*Notice) {
// It waits till there is at least one matching notice or the context is
// cancelled. If there are existing notices that match the filter,
// WaitNotices will return them immediately.
//
// Note that WaitNotices releases the state lock while waiting.
func (s *State) WaitNotices(ctx context.Context, filter *NoticeFilter) ([]*Notice, error) {
s.reading()

Expand Down Expand Up @@ -426,7 +428,8 @@ func (s *State) WaitNotices(ctx context.Context, filter *NoticeFilter) ([]*Notic
defer stop()

for {
// Wait till a new notice occurs or a context is cancelled.
// Wait till a new notice occurs or a context is cancelled. Note that
// noticeCond wraps the state lock, so this is what unlocks it.
s.noticeCond.Wait()

// If this context is cancelled, return the error.
Expand Down

0 comments on commit 9986cdf

Please sign in to comment.