Add custom panic hook for RPC port bind

This commit is contained in:
Tyera Eulberg 2018-08-18 23:07:07 -06:00 committed by Tyera Eulberg
parent 86c1d97c13
commit be4824c955
1 changed files with 6 additions and 0 deletions

View File

@ -8,6 +8,7 @@ use service::Service;
use signature::{Pubkey, Signature};
use std::mem;
use std::net::SocketAddr;
use std::panic;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread::{self, Builder, JoinHandle};
@ -28,6 +29,10 @@ impl JsonRpcService {
let rpc = RpcSolImpl;
io.extend_with(rpc.to_delegate());
panic::set_hook(Box::new(move |_| {
warn!("JSON RPC service unavailable: unable to bind to RPC port {}. \nMake sure this port is not already in use by another application", rpc_addr.port());
}));
let server =
ServerBuilder::with_meta_extractor(io, move |_req: &hyper::Request| Meta {
request_processor: request_processor.clone(),
@ -37,6 +42,7 @@ impl JsonRpcService {
]))
.start_http(&rpc_addr)
.unwrap();
let _ = panic::take_hook();
loop {
if exit.load(Ordering::Relaxed) {
server.close();