Calling event_base_loopbreak before event_base_dispatch has no effect. Fix this by calling event_base_loopbreak from the event's callback. From the documentation:event_base_loop() will abort the loop after the next event is completed; event_base_loopbreak() is typically invoked from this event's callback. This behavior is analogous to the "break;" statement.
The issue was:
When I run
./bitcoind -regtest -whitebind=bla
I expect a clean shutdown with Error: Cannot resolve -whitebind address: 'bla'.
However sometimes my node doesn't stop and freezes (shutdown never finishes).
Backport of Core PR16405