Skip to content
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

Dropping EventLoopHandle after running a request causes the program to hang. #80

Closed
abrodersen opened this issue Dec 2, 2017 · 8 comments
Labels

Comments

@abrodersen
Copy link

abrodersen commented Dec 2, 2017

Dropping EventLoopHandle before dropping Web3<T> causes a hang if at least one request has been issued. Example code:

extern crate web3;

use web3::futures::Future;

fn main() {
  let (eloop, http) = web3::transports::Http::new("http://localhost:8545").unwrap();
  let web3 = web3::Web3::new(http);
  let _accounts = web3.eth().accounts().wait().unwrap();

  drop(eloop);
}

This became an issue when I created a struct that owned both EventLoopHandle and Web3<T>. If my struct fields were in the wrong order, the program would hang when attempting to drop my struct. If I switched the order of the fields, the program would run to completion.

@tomusdrw
Copy link
Owner

tomusdrw commented Dec 5, 2017

Good catch it's really interesting why it fails.

@aleksuss
Copy link

I have the same issue

@aleksuss
Copy link

FYI: But if I use an event loop from tokio everything is OK

@tomusdrw tomusdrw added the bug label Feb 7, 2018
@yangby-cryptape
Copy link

yangby-cryptape commented Jul 18, 2018

After test, I think it is hang at EventLoopHandle::Drop.

Move the event_loop into another thread and ignore it can avoid this bug (uncleanly exit?).

@yangby-cryptape
Copy link

Finally, I have known what happened.

It hangs at event_loop.turn(None);, before checking the done flag.

When we want to shutdown the event_loop, we stop send any new message, and set the done flag.
But the event_loop will check the done flag after next message, so it hangs at waiting for next message.
So, it hangs.

The simplest way (but stupid?) to fix this bug is: after set the done flag, send to it a new message.

@tomusdrw
Copy link
Owner

Perhaps we could supply a timeout to turn?

synlestidae added a commit to synlestidae/rust-web3 that referenced this issue Jul 20, 2018
@synlestidae
Copy link
Contributor

@yangby-cryptape is correct I think. I added self.remote.spawn(|_| Ok(())) before the thread join. It seems to fix it on my end.

#144

@tomusdrw
Copy link
Owner

Resolved via #144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants