Add custom panic hook for RPC port bind
This commit is contained in:
committed by
Tyera Eulberg
parent
86c1d97c13
commit
be4824c955
@ -8,6 +8,7 @@ use service::Service;
|
|||||||
use signature::{Pubkey, Signature};
|
use signature::{Pubkey, Signature};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
use std::panic;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread::{self, Builder, JoinHandle};
|
use std::thread::{self, Builder, JoinHandle};
|
||||||
@ -28,6 +29,10 @@ impl JsonRpcService {
|
|||||||
let rpc = RpcSolImpl;
|
let rpc = RpcSolImpl;
|
||||||
io.extend_with(rpc.to_delegate());
|
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 =
|
let server =
|
||||||
ServerBuilder::with_meta_extractor(io, move |_req: &hyper::Request| Meta {
|
ServerBuilder::with_meta_extractor(io, move |_req: &hyper::Request| Meta {
|
||||||
request_processor: request_processor.clone(),
|
request_processor: request_processor.clone(),
|
||||||
@ -37,6 +42,7 @@ impl JsonRpcService {
|
|||||||
]))
|
]))
|
||||||
.start_http(&rpc_addr)
|
.start_http(&rpc_addr)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let _ = panic::take_hook();
|
||||||
loop {
|
loop {
|
||||||
if exit.load(Ordering::Relaxed) {
|
if exit.load(Ordering::Relaxed) {
|
||||||
server.close();
|
server.close();
|
||||||
|
Reference in New Issue
Block a user