Skip to content

warmuper.WaitAndClose: cancel work before wait#20332

Merged
AskAlexSharov merged 2 commits into
release/3.4from
alex/warmuper_close_34
Apr 5, 2026
Merged

warmuper.WaitAndClose: cancel work before wait#20332
AskAlexSharov merged 2 commits into
release/3.4from
alex/warmuper_close_34

Conversation

@AskAlexSharov

Copy link
Copy Markdown
Collaborator

before:

  • seems we never close Warmuper - because WaitAndClose switching atomic.
  • seems we wait-first and then cancel/close work channel - it's wrong because WaitAndClose() called when warmup not needed anymore (commitment calc finished):
warmuper.Start()
defer warmuper.WaitAndClose()

PR: canceling first and then wait gorouines to finish

@AskAlexSharov AskAlexSharov merged commit 6b09b8a into release/3.4 Apr 5, 2026
22 checks passed
@AskAlexSharov AskAlexSharov deleted the alex/warmuper_close_34 branch April 5, 2026 13:46
AskAlexSharov added a commit that referenced this pull request Apr 5, 2026
before: 
- seems we never close Warmuper - because WaitAndClose switching atomic.
- seems we wait-first and then cancel/close work channel - it's wrong
because `WaitAndClose()` called when warmup not needed anymore
(commitment calc finished):
```
warmuper.Start()
defer warmuper.WaitAndClose()
```		


PR: canceling first and then wait gorouines to finish
@AskAlexSharov AskAlexSharov requested a review from Copilot April 6, 2026 00:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts warmup worker shutdown semantics so warmup work is canceled before waiting for goroutines to exit, addressing cases where warmup is no longer needed (e.g., deferred cleanup during commitment processing).

Changes:

  • Replace Warmuper.WaitAndClose() with Warmuper.CloseAndWait() that calls Close() first, then waits for worker goroutines.
  • Update HexPatriciaHashed.Process to defer CloseAndWait() instead of WaitAndClose().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
execution/commitment/warmuper.go Renames/reworks shutdown helper to cancel work before waiting on workers.
execution/commitment/hex_patricia_hashed.go Switches deferred warmuper cleanup to the new shutdown helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +320 to +325
// CloseAndWait cancel and waits for all warmup work
func (w *Warmuper) CloseAndWait() {
w.Close()
if w.g != nil {
_ = w.g.Wait()
}

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CloseAndWait calls w.Close() unconditionally. If Start() returned early (e.g., cfg.NumWorkers <= 0), w.work is never initialized and Close() will panic when it tries to close a nil channel. Consider making Close()/CloseAndWait() safe when not started (e.g., guard on w.work != nil / w.g != nil, or restructure Start() so work is always initialized before Close can run).

Copilot uses AI. Check for mistakes.
return // Already closed
}
w.Wait()
// CloseAndWait cancel and waits for all warmup work

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment has grammatical issues: "CloseAndWait cancel and waits for all warmup work" should be something like "CloseAndWait cancels and waits for all warmup work" (and ideally mention that it cancels in-flight warmup rather than draining it).

Suggested change
// CloseAndWait cancel and waits for all warmup work
// CloseAndWait cancels warmup work and waits for in-flight workers to exit.

Copilot uses AI. Check for mistakes.
Comment on lines +320 to +325
// CloseAndWait cancel and waits for all warmup work
func (w *Warmuper) CloseAndWait() {
w.Close()
if w.g != nil {
_ = w.g.Wait()
}

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes warmuper shutdown semantics (cancel-before-wait) and introduces a new public method CloseAndWait, but there doesn't appear to be test coverage exercising Process() with warmup.Enabled=true (existing hex_patricia_hashed tests pass WarmupConfig{}), nor a unit test that CloseAndWait is safe/idempotent. Adding a test that enables warmup and asserts CloseAndWait doesn't leak goroutines / doesn't panic (including NumWorkers=0 edge case) would help prevent regressions.

Copilot uses AI. Check for mistakes.
github-merge-queue Bot pushed a commit that referenced this pull request Apr 6, 2026
…x, xsync fix, warmuper fix, logs debug, unused code (#20337)

Cherry-picks from release/3.4 to main:

- integrity: blk-range chk to pre-build "changed keys" index before calc
state root (#20302)
- up gql and grpc (#20304)
- stepSize: all tooling to use `tx.Debug().StepSize()` instead of
`DefaultStepSize` constant (#20280)
- db/state: fix CursorHeap tie-break to prefer RAM over DB over FILE
(#20318)
- xsync deprecated use fix (#20331)
- warmuper.WaitAndClose: cancel work before wait (#20332)
- logs: move some Info logs to Debug level (to simplify logs for Users)
(#20329)
- db: unused code remove (#20334)

---------

Co-authored-by: moskud <sudeepdino008@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants