-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix client not being dropped on shutdown #7695
Conversation
It looks like @andresilva signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
Please test this locally by adding a |
99b316f
to
8af73b3
Compare
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.
Couple of minor grumbles, otherwise looks good.
@@ -856,6 +848,9 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R | |||
open_dapp(&cmd.dapps_conf, &cmd.http_conf, &dapp)?; | |||
} | |||
|
|||
// Create a weak reference to the client so that we can wait on shutdown until it is dropped |
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.
Something wierd with the indentation
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.
Spaces.
parity/run.rs
Outdated
raise_fd_limit(); | ||
|
||
fn wait<T>(res: Result<((bool, Option<String>), Weak<T>), String>) -> Result<(bool, Option<String>), String> { | ||
res.map(|r| { |
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.
You should be able to destructure here:
|(restart, weak_client)| {
...
}
parity/run.rs
Outdated
fn wait_for_drop<T>(w: Weak<T>) { | ||
let sleep_duration = Duration::from_secs(1); | ||
let warn_timeout = Duration::from_secs(30); | ||
let max_timeout = Duration::from_secs(120); |
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.
IMHO that's a bit too low (especially on HDD). Can we have like 5minutes here?
parity/run.rs
Outdated
let mut warned = false; | ||
|
||
loop { | ||
{ |
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.
Why do we need that additional block?
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.
If the upgrade
is successful is it dropped right away or only at the end of the loop iteration? I just wanted to make sure it was dropped right away (before sleeping).
parity/run.rs
Outdated
} | ||
} | ||
|
||
if instant.elapsed() > max_timeout { |
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.
Nitpick. Imho this loop is more concise and cleaner for me (but don't have strong opinion):
while instance.elapsed() < max_timeout {
if w.upgrade().is_none() {
return;
}
if !warned && instant.elapsed() > warn_timeout {
warned = true;
warn!(...);
}
}
warn('unclean');
My two cents: tested it for some time (by adding |
* parity: wait for client to drop on shutdown * parity: fix grumbles in shutdown wait * parity: increase shutdown timeouts
* parity: wait for client to drop on shutdown * parity: fix grumbles in shutdown wait * parity: increase shutdown timeouts
* parity: wait for client to drop on shutdown * parity: fix grumbles in shutdown wait * parity: increase shutdown timeouts
* Filter-out nodes.json (#7716) * Filter-out nodes.json * network: sort node table nodes by failure ratio * network: fix node table tests * network: fit node failure percentage into buckets of 5% * network: consider number of attempts in sorting of node table * network: fix node table grumbles * Fix client not being dropped on shutdown (#7695) * parity: wait for client to drop on shutdown * parity: fix grumbles in shutdown wait * parity: increase shutdown timeouts * Wrap --help output to 120 characters (#7626) * Update Clap dependency and remove workarounds * WIP * Remove line breaks in help messages for now * Multiple values can only be separated by commas (closes #7428) * Grumbles; refactor repeating code; add constant * Use a single Wrapper rather than allocate a new one for each call * Wrap --help to 120 characters rather than 100 characters
* Filter-out nodes.json (#7716) * Filter-out nodes.json * network: sort node table nodes by failure ratio * network: fix node table tests * network: fit node failure percentage into buckets of 5% * network: consider number of attempts in sorting of node table * network: fix node table grumbles * Fix client not being dropped on shutdown (#7695) * parity: wait for client to drop on shutdown * parity: fix grumbles in shutdown wait * parity: increase shutdown timeouts * Wrap --help output to 120 characters (#7626) * Update Clap dependency and remove workarounds * WIP * Remove line breaks in help messages for now * Multiple values can only be separated by commas (closes #7428) * Grumbles; refactor repeating code; add constant * Use a single Wrapper rather than allocate a new one for each call * Wrap --help to 120 characters rather than 100 characters
I noticed that the
Client
was not being dropped on shutdown, this also meant that theDatabase
was not dropped and that RocksDB wasn't properly closed. I'm not sure why it's necessary to wait for theClient
to drop, maybe there's some other thread holding a reference to it that takes a while to die?I started by converting some stuff to
Weak
on the RPC clients and it fixed the issue. And then I implemented the wait mechanism (suggested by @tomusdrw) and I noticed that declaringWeak
references was no longer necessary.It took me a really long time to figure this out (and incremental compilation really helped). 😐
Should fix #6213, #7518, #7334.