Skip to content

Commit

Permalink
graph, node: Add descriptive comments, restructure shutdown sending
Browse files Browse the repository at this point in the history
  • Loading branch information
fordN committed Dec 4, 2018
1 parent fbe925c commit 8e877eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
26 changes: 16 additions & 10 deletions graph/src/util/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use slog_async;
use slog_envlogger;
use slog_term;
use std::sync::Mutex;
use std::{env, panic};
use std::time::{Duration, Instant};
use std::{env, panic, process, thread};

pub fn logger(show_debug: bool) -> Logger {
let decorator = slog_term::TermDecorator::new().build();
Expand Down Expand Up @@ -73,14 +74,19 @@ pub fn register_panic_hook(
}
};

if let Ok(ref mut mutex) = shutdown_sender.lock() {
if let Some(sender) = mutex.take() {
sender
.send(())
.map(|_| ())
.map_err(|_| ())
.expect("Failed to signal shutdown")
}
};
// Send a shutdown signal to main which will attempt to cleanly shutdown the runtime
// After sending shutdown, the thread sleeps for 3 seconds then forces the process to
// exit because the shutdown is not always able to cleanly exit all workers
shutdown_sender
.lock()
.unwrap()
.take()
.expect("Shutdown signal already sent")
.send(())
.map(|_| ())
.map_err(|_| ())
.expect("Failed to signal shutdown");
thread::sleep(Duration::from_millis(3000));
process::exit(1);
}));
}
7 changes: 2 additions & 5 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ use std::env;
use std::net::ToSocketAddrs;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::{env, process, thread};
use url::Url;

use graph::components::{forward, forward2};
use graph::prelude::{JsonRpcServer as JsonRpcServerTrait, *};
Expand Down Expand Up @@ -62,6 +60,7 @@ fn main() {
let timer = Timer::default();
let timer_handle = timer.handle();

// Shutdown the runtime after a panic
std::thread::spawn(|| {
shutdown_receiver
.wait()
Expand All @@ -70,8 +69,6 @@ fn main() {
.shutdown_now()
.wait()
.expect("Failed to shutdown Tokio Runtime");
thread::sleep(Duration::from_millis(3000));
process::exit(1)
}).expect("Runtime shutdown process did not finish");
});

Expand Down Expand Up @@ -497,7 +494,7 @@ fn async_main() -> impl Future<Item = (), Error = ()> + Send + 'static {
.expect("Failed to start GraphQL subscription server"),
);

future::ok(())
future::empty()
}

/// Parses an Ethereum connection string and returns the network name and Ethereum node.
Expand Down

0 comments on commit 8e877eb

Please sign in to comment.