Skip to content

blocksync: wait for poolRoutine to stop in (*Reactor).OnStop (backport #1879)#1982

Merged
melekes merged 1 commit intov0.38.xfrom
mergify/bp/v0.38.x/pr-1879
Jan 7, 2024
Merged

blocksync: wait for poolRoutine to stop in (*Reactor).OnStop (backport #1879)#1982
melekes merged 1 commit intov0.38.xfrom
mergify/bp/v0.38.x/pr-1879

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Jan 7, 2024

This is an automatic backport of pull request #1879 done by Mergify.


Mergify commands and options

More conditions and actions can be found in the documentation.

You can also trigger Mergify actions by commenting on this pull request:

  • @Mergifyio refresh will re-evaluate the rules
  • @Mergifyio rebase will rebase this PR on its base branch
  • @Mergifyio update will merge the base branch into this PR
  • @Mergifyio backport <destination> will backport this PR on <destination> branch

Additionally, on Mergify dashboard you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com

* blocksync: wait for poolRoutine to stop in (*Reactor).OnStop

blocksync.(*Reactor).poolRoutine goroutine lifetime was not supervised,
so OnStop returning did not provide a guarantee that it was done.  As a
result, the other services could be stopped and a subsequent call to
bcR.blockExec.ApplyBlock would cause a panic, typically a leveldb
closed error.

This change uses a sync.WaitGroup to ensure that OnStop returns after
poolRoutine has returned.

This also triggers the poolRoutine method to return on a signal from
bcR.pool.Quit() instead of just bcR.Quit(), which seems to be important
as (*Reactor).OnStop itself can only stop the BlockPool (bcR.pool), while
the BaseReactor.BaseService's quit channel will only be closed _after_
(*Reactor).OnStop has returned.

* rename wg field, comment on strayish select before retry

* break poolRoutine on either Quit before quick retry

* update changelog

* break the loop with an IsRunning check

* do the waitgroup Add and Defer at the same site for clarity

* check both services IsRunning in poolRoutine

* fix oopsie

---------

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
(cherry picked from commit 7ea352e)
@mergify mergify bot requested a review from a team as a code owner January 7, 2024 05:32
@melekes melekes merged commit d707110 into v0.38.x Jan 7, 2024
@melekes melekes deleted the mergify/bp/v0.38.x/pr-1879 branch January 7, 2024 05:50
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.

2 participants