Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 162
Hold runtime lock during stop and reduce timeout values across the board#538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -126,8 +126,9 @@ pub use builder::NodeBuilder as Builder; | ||
| use chain::ChainSource; | ||
| use config::{ | ||
| default_user_config, may_announce_channel, ChannelConfig, Config, NODE_ANN_BCAST_INTERVAL, | ||
| PEER_RECONNECTION_INTERVAL, RGS_SYNC_INTERVAL, | ||
| default_user_config, may_announce_channel, ChannelConfig, Config, | ||
| LDK_EVENT_HANDLER_SHUTDOWN_TIMEOUT_SECS, NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL, | ||
| RGS_SYNC_INTERVAL, | ||
| }; | ||
| use connection::ConnectionManager; | ||
| use event::{EventHandler, EventQueue}; | ||
| @@ -643,7 +644,12 @@ impl Node { | ||
| /// | ||
| /// After this returns most API methods will return [`Error::NotRunning`]. | ||
| pub fn stop(&self) -> Result<(), Error> { | ||
| let runtime = self.runtime.write().unwrap().take().ok_or(Error::NotRunning)?; | ||
| // We hold the write lock for the duration of this method to avoid any conflicts with | ||
| // inflight tasks when users would potentially concurrently try restart the node before | ||
| // `stop` returned. | ||
| let mut runtime_lock = self.runtime.write().unwrap(); | ||
tnull marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| let runtime = runtime_lock.take().ok_or(Error::NotRunning)?; | ||
| #[cfg(tokio_unstable)] | ||
| let metrics_runtime = Arc::clone(&runtime); | ||
| @@ -672,13 +678,10 @@ impl Node { | ||
| let event_handling_stopped_logger = Arc::clone(&self.logger); | ||
| let mut event_handling_stopped_receiver = self.event_handling_stopped_sender.subscribe(); | ||
| // FIXME: For now, we wait up to 100 secs (BDK_WALLET_SYNC_TIMEOUT_SECS + 10) to allow | ||
| // event handling to exit gracefully even if it was blocked on the BDK wallet syncing. We | ||
| // should drop this considerably post upgrading to BDK 1.0. | ||
| let timeout_res = tokio::task::block_in_place(move || { | ||
| runtime.block_on(async { | ||
| tokio::time::timeout( | ||
| Duration::from_secs(100), | ||
| Duration::from_secs(LDK_EVENT_HANDLER_SHUTDOWN_TIMEOUT_SECS), | ||
| event_handling_stopped_receiver.changed(), | ||
| ) | ||
| .await | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What changed so that huge values are 'hopefully' not required anymore? Did they remove that central mutex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side question: isn't it better to not have a timeout? I don't know if it is desired to have background processes running when
stopreturns.For the BDK timeout, it also seems that
stopreturnsOk(), so also no indication other than log that something is wrong?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they dropped that mutex that used to be held for the entire duration of syncing the wallet with BDK 1.0. Here, we just do (late) accommodations since the behavior since the upgrade improved considerably.
Hmm, I'm not sure. In general we should never reach that timeout, even though we recently got some reports to the contrary. But not having a timeout at all might also lead users to just kill the process after some (even more random time), which might have worse consequences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a rationale for the new timeout values? I'd imagine they should match BDK timeouts plus something? Or is the BDK timeout behavior complex and not reducable to a single value?
So when "our" timeout expires and the node is reported to be stopped, wouldn't the process then typically be terminated anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure what you mean with 'BDK timeout'? The individual electrum/esplora clients might have separate timeouts on a per-request basis, is that what you were referring to here?
Yes, but we'd have more control over what we require finishing before timing out. Although, indeed, if we're currently would for some reason get blocked in the events processing and just timeout and move on, we might miss the final persistence round of the BP on shutdown.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant whatever we are waiting for that is outside ldk-node.
Doesn't this mean that we're better off / safer without the timeout? Or should the timeout be restricted to just the external processes and not the whole event handler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the timeout generally gives us control on which parts of the shutdown we wait and which we might skip. We could see to eventually do it in a more fine-grained fashion, but generally the timeout is really meant to be a last resort, as we don't expect the event handler to block for longer durations at a time.
FWIW, I recently start playing around with wrapping the event handling method itself in a timeout (rather than timing out waiting on the BP to shut down), which would at least mean the BP would shutdown 'normally'. However, this would mean we'd need to error with
ReplayEventif we hit the timeout, and I'm not fully convinced yet this is the way to go, but maybe we should.