Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix client not being dropped on shutdown #7695

Merged
merged 3 commits into from
Jan 31, 2018
Merged

Fix client not being dropped on shutdown #7695

merged 3 commits into from
Jan 31, 2018

Conversation

andresilva
Copy link
Contributor

I noticed that the Client was not being dropped on shutdown, this also meant that the Database was not dropped and that RocksDB wasn't properly closed. I'm not sure why it's necessary to wait for the Client 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 declaring Weak 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.

@parity-cla-bot
Copy link

It looks like @andresilva signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@andresilva
Copy link
Contributor Author

Please test this locally by adding a println to the Database Drop instance. Also check if the timeouts for shutdown are reasonable.

@andresilva andresilva added B0-patch M4-core ⛓ Core client code / Rust. A0-pleasereview 🤓 Pull request needs code review. labels Jan 25, 2018
Copy link
Collaborator

@tomusdrw tomusdrw left a 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
Copy link
Collaborator

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

Copy link
Contributor Author

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| {
Copy link
Collaborator

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);
Copy link
Collaborator

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 {
{
Copy link
Collaborator

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?

Copy link
Contributor Author

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 {
Copy link
Collaborator

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');

@tomusdrw tomusdrw added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 30, 2018
@svyatonik svyatonik added A0-pleasereview 🤓 Pull request needs code review. and removed A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. labels Jan 31, 2018
@svyatonik
Copy link
Collaborator

My two cents: tested it for some time (by adding println) yesterday - have seen the printed line every time. Haven't tested with light client, though.

@5chdn 5chdn merged commit 4763887 into master Jan 31, 2018
@5chdn 5chdn deleted the fix-shutdown branch January 31, 2018 10:41
@5chdn 5chdn added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 31, 2018
andresilva added a commit that referenced this pull request Jan 31, 2018
* parity: wait for client to drop on shutdown

* parity: fix grumbles in shutdown wait

* parity: increase shutdown timeouts
@andresilva andresilva mentioned this pull request Jan 31, 2018
andresilva added a commit that referenced this pull request Jan 31, 2018
* parity: wait for client to drop on shutdown

* parity: fix grumbles in shutdown wait

* parity: increase shutdown timeouts
@andresilva andresilva mentioned this pull request Jan 31, 2018
andresilva added a commit that referenced this pull request Jan 31, 2018
* parity: wait for client to drop on shutdown

* parity: fix grumbles in shutdown wait

* parity: increase shutdown timeouts
5chdn pushed a commit that referenced this pull request Jan 31, 2018
* 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
5chdn pushed a commit that referenced this pull request Jan 31, 2018
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pure virtual method called + terminate called recursively
5 participants