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

Setup Forest execution threads #236

Merged
merged 7 commits into from
Feb 20, 2020
Merged

Setup Forest execution threads #236

merged 7 commits into from
Feb 20, 2020

Conversation

austinabell
Copy link
Contributor

@austinabell austinabell commented Feb 20, 2020

Summary of changes
Changes introduced in this pull request:

Currently, the networking service was running in the main thread. This was always planned to run in seperate thread and this needs to change for the changes I'm working on. PRing in now because it can be isolated from the other changes I'm making but have testing running multiple threads and the SIGINT handler functions as intended.

To summarize the SIGINT handler, pressing once will drop all threads (and when services need to be carefully shut down that logic can be added) and a second press will force exit the main thread. With thread/task sleeps you can test this yourself.

Also the process::exit() will not call destructors on any thread and will exit the process immediately, docs: https://doc.rust-lang.org/std/process/fn.exit.html and maybe should change the exit code to a non-zero one? Makes sense to me but I'm okay with changing

Reference issue to close (if applicable)

Closes

Other information and links


task::block_on(async move {
// Start libp2p service
let lp2p_service = Libp2pService::new(logger, &config.network, net_keypair);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just call it p2p_service

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unchanged in this PR, but changed it haha

if running.load(Ordering::SeqCst) > 0 {
// TODO change dropping threads to gracefully shutting down services
// or implement drop on components with sensitive shutdown
drop(lp2p_thread);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: p2p_thread

@austinabell
Copy link
Contributor Author

austinabell commented Feb 20, 2020

@ansermino Changed to blocking on channel from ctrlc thread to avoid that busy loop, sorry to make change after review

ctrlc::set_handler(move || {
let prev = running.fetch_add(1, Ordering::SeqCst);
if prev == 0 {
println!("Got interrupt, shutting down...");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "Got interrupted, shutting down..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the noun version makes more sense in this context, anyone else have a preference? Idrc happy to change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with either. They're both clear enough. Maybe "Shutdown signal received... Shutting down" might be better? Again, indifferent though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha to avoid going down this rabbit hole I'm just going to pull in as is, I'll approve any change if anyone cares that much :)

@austinabell austinabell merged commit a65794b into master Feb 20, 2020
@austinabell austinabell deleted the austin/node/threads branch February 20, 2020 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants