Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Restore panic handler
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Aug 4, 2016
1 parent ad1d3cc commit 7634f11
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 29 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ name = "parity"
[profile.release]
debug = true
lto = false
panic = "abort"

1 change: 0 additions & 1 deletion ethcore/src/block_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use views::*;
use header::*;
use service::*;
use client::BlockStatus;
use util::panics::*;

pub use types::block_queue_info::BlockQueueInfo;

Expand Down
1 change: 0 additions & 1 deletion ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use util::{journaldb, rlp, Bytes, View, PerfTimer, Itertools, Mutex, RwLock};
use util::journaldb::JournalDB;
use util::rlp::{UntrustedRlp};
use util::numbers::*;
use util::panics::*;
use util::sha3::*;
use util::kvdb::*;

Expand Down
1 change: 1 addition & 0 deletions ethcore/src/json_tests/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use spec::Genesis;
use ethjson;
use ethjson::blockchain::BlockChain;
use miner::Miner;
use io::IoChannel;

pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
init_log();
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use util::*;
use io::*;
use util::panics::*;
use spec::Spec;
use error::*;
use client::{Client, ClientConfig, ChainNotify};
Expand Down Expand Up @@ -60,6 +59,7 @@ impl ClientService {
{
let panic_handler = PanicHandler::new_in_arc();
let io_service = try!(IoService::<ClientIoMessage>::start());
panic_handler.forward_from(&io_service);

info!("Configured for {} using {} engine", Colour::White.bold().paint(spec.name.clone()), Colour::Yellow.bold().paint(spec.engine.name()));
if spec.fork_name.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion parity/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::path::Path;
use std::sync::Arc;
use rustc_serialize::hex::FromHex;
use ethcore_logger::{setup_log, Config as LogConfig};
use util::panics::{PanicHandler, ForwardPanic};
use io::{PanicHandler, ForwardPanic};
use util::{PayloadInfo, ToPretty};
use ethcore::service::ClientService;
use ethcore::client::{Mode, DatabaseCompactionProfile, Switch, VMType, BlockImportError, BlockChainClient, BlockID};
Expand Down
2 changes: 1 addition & 1 deletion parity/dapps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::sync::Arc;
use std::net::SocketAddr;
use util::panics::PanicHandler;
use io::PanicHandler;
use rpc_apis;
use helpers::replace_home;

Expand Down
2 changes: 1 addition & 1 deletion parity/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::fmt;
use std::sync::Arc;
use std::net::SocketAddr;
use util::panics::PanicHandler;
use io::PanicHandler;
use ethcore_rpc::{RpcServerError, RpcServer as Server};
use jsonipc;
use rpc_apis;
Expand Down
2 changes: 1 addition & 1 deletion parity/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use ethcore_logger::{Config as LogConfig, setup_log};
use ethcore_rpc::NetworkSettings;
use ethsync::NetworkConfiguration;
use util::{Colour, version, U256};
use util::panics::{MayPanic, ForwardPanic, PanicHandler};
use io::{MayPanic, ForwardPanic, PanicHandler};
use ethcore::client::{Mode, Switch, DatabaseCompactionProfile, VMType, ChainNotify};
use ethcore::service::ClientService;
use ethcore::account_provider::AccountProvider;
Expand Down
2 changes: 1 addition & 1 deletion parity/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::io;
use std::sync::Arc;
use std::path::PathBuf;
use ansi_term::Colour;
use util::panics::{ForwardPanic, PanicHandler};
use io::{ForwardPanic, PanicHandler};
use util::path::restrict_permissions_owner;
use rpc_apis;
use ethcore_signer as signer;
Expand Down
1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ serde = "0.7.0"
serde_json = "0.7.0"
jsonrpc-core = "2.0"
jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git" }
ethcore-io = { path = "../util/io" }
ethcore-util = { path = "../util" }
ethcore = { path = "../ethcore" }
ethash = { path = "../ethash" }
Expand Down
3 changes: 2 additions & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern crate jsonrpc_core;
extern crate jsonrpc_http_server;
#[macro_use]
extern crate ethcore_util as util;
extern crate ethcore_io as io;
extern crate ethcore;
extern crate ethsync;
extern crate transient_hashmap;
Expand All @@ -41,7 +42,7 @@ extern crate ethcore_devtools as devtools;

use std::sync::Arc;
use std::net::SocketAddr;
use util::panics::PanicHandler;
use io::PanicHandler;
use self::jsonrpc_core::{IoHandler, IoDelegate};

pub use jsonrpc_http_server::{ServerBuilder, Server, RpcServerError};
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/tests/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use ethcore::miner::{MinerOptions, GasPricer, MinerService, ExternalMiner, Miner
use ethcore::account_provider::AccountProvider;
use devtools::RandomTempPath;
use util::Hashable;
use util::io::IoChannel;
use io::IoChannel;
use util::{U256, H256, Uint};
use jsonrpc_core::IoHandler;
use ethjson::blockchain::BlockChain;
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/tests/mocked/ethcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use v1::tests::helpers::TestMinerService;
use v1::helpers::ConfirmationsQueue;
use ethcore::client::{TestBlockChainClient};
use util::log::RotatingLogger;
use util::network_settings::NetworkSettings;
use v1::helpers::NetworkSettings;

fn miner_service() -> Arc<TestMinerService> {
Arc::new(TestMinerService::default())
Expand Down
3 changes: 1 addition & 2 deletions rpc/src/v1/tests/mocked/manage_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use ethsync::{ManageNetwork, NetworkConfiguration};
use util;

pub struct TestManageNetwork;

Expand All @@ -27,5 +26,5 @@ impl ManageNetwork for TestManageNetwork {
fn add_reserved_peer(&self, _peer: String) -> Result<(), String> { Ok(()) }
fn start_network(&self) {}
fn stop_network(&self) {}
fn network_config(&self) -> NetworkConfiguration { NetworkConfiguration::from(util::NetworkConfiguration::new_local()) }
fn network_config(&self) -> NetworkConfiguration { NetworkConfiguration::new_local() }
}
1 change: 1 addition & 0 deletions signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ log = "0.3"
env_logger = "0.3"
ws = { git = "https://github.com/ethcore/ws-rs.git", branch = "stable" }
ethcore-util = { path = "../util" }
ethcore-io = { path = "../util/io" }
ethcore-rpc = { path = "../rpc" }
parity-dapps-signer = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6", optional = true}

Expand Down
1 change: 1 addition & 0 deletions signer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern crate env_logger;
extern crate rand;

extern crate ethcore_util as util;
extern crate ethcore_io as io;
extern crate ethcore_rpc as rpc;
extern crate jsonrpc_core;
extern crate ws;
Expand Down
2 changes: 1 addition & 1 deletion signer/src/ws_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::default::Default;
use std::ops::Drop;
use std::sync::Arc;
use std::net::SocketAddr;
use util::panics::{PanicHandler, OnPanicListener, MayPanic};
use io::{PanicHandler, OnPanicListener, MayPanic};
use jsonrpc_core::{IoHandler, IoDelegate};
use rpc::{Extendable, ConfirmationsQueue};

Expand Down
4 changes: 4 additions & 0 deletions sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ impl NetworkConfiguration {
From::from(BasicNetworkConfiguration::new())
}

pub fn new_local() -> Self {
From::from(BasicNetworkConfiguration::new_local())
}

fn validate(&self) -> Result<(), AddrParseError> {
if let Some(ref addr) = self.listen_address {
try!(SocketAddr::from_str(&addr));
Expand Down
7 changes: 4 additions & 3 deletions sync/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use util::*;
use network::*;
use ethcore::client::{TestBlockChainClient, BlockChainClient};
use ethcore::header::BlockNumber;
use io::SyncIo;
use sync_io::SyncIo;
use chain::ChainSync;
use ::SyncConfig;

Expand Down Expand Up @@ -48,7 +49,7 @@ impl<'p> SyncIo for TestIo<'p> {
false
}

fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError> {
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
self.queue.push_back(TestPacket {
data: data,
packet_id: packet_id,
Expand All @@ -57,7 +58,7 @@ impl<'p> SyncIo for TestIo<'p> {
Ok(())
}

fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError> {
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
self.queue.push_back(TestPacket {
data: data,
packet_id: packet_id,
Expand Down
2 changes: 1 addition & 1 deletion sync/src/tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use super::super::NetworkConfiguration;
use util::NetworkConfiguration as BasicNetworkConfiguration;
use network::NetworkConfiguration as BasicNetworkConfiguration;
use std::convert::From;
use ipc::binary::{serialize, deserialize};

Expand Down
2 changes: 2 additions & 0 deletions util/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern crate parking_lot;

mod service;
mod worker;
mod panics;

use mio::{EventLoop, Token};
use std::fmt;
Expand Down Expand Up @@ -130,6 +131,7 @@ pub use service::IoService;
pub use service::IoChannel;
pub use service::IoManager;
pub use service::TOKENS_PER_HANDLER;
pub use panics::{PanicHandler, MayPanic, OnPanicListener, ForwardPanic};

#[cfg(test)]
mod tests {
Expand Down
File renamed without changes.
24 changes: 19 additions & 5 deletions util/io/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crossbeam::sync::chase_lev;
use slab::Slab;
use {IoError, IoHandler};
use worker::{Worker, Work, WorkType};

use panics::*;
use parking_lot::{RwLock};
use std::sync::{Condvar as SCondvar, Mutex as SMutex};

Expand Down Expand Up @@ -173,7 +173,7 @@ pub struct IoManager<Message> where Message: Send + Sync {

impl<Message> IoManager<Message> where Message: Send + Sync + Clone + 'static {
/// Creates a new instance and registers it with the event loop.
pub fn start(event_loop: &mut EventLoop<IoManager<Message>>) -> Result<(), IoError> {
pub fn start(panic_handler: Arc<PanicHandler>, event_loop: &mut EventLoop<IoManager<Message>>) -> Result<(), IoError> {
let (worker, stealer) = chase_lev::deque();
let num_workers = 4;
let work_ready_mutex = Arc::new(SMutex::new(()));
Expand All @@ -185,6 +185,7 @@ impl<Message> IoManager<Message> where Message: Send + Sync + Clone + 'static {
IoChannel::new(event_loop.channel()),
work_ready.clone(),
work_ready_mutex.clone(),
panic_handler.clone(),
)
).collect();

Expand Down Expand Up @@ -344,21 +345,34 @@ impl<Message> IoChannel<Message> where Message: Send + Clone {
/// General IO Service. Starts an event loop and dispatches IO requests.
/// 'Message' is a notification message type
pub struct IoService<Message> where Message: Send + Sync + Clone + 'static {
panic_handler: Arc<PanicHandler>,
thread: Option<JoinHandle<()>>,
host_channel: Sender<IoMessage<Message>>,
}

impl<Message> MayPanic for IoService<Message> where Message: Send + Sync + Clone + 'static {
fn on_panic<F>(&self, closure: F) where F: OnPanicListener {
self.panic_handler.on_panic(closure);
}
}

impl<Message> IoService<Message> where Message: Send + Sync + Clone + 'static {
/// Starts IO event loop
pub fn start() -> Result<IoService<Message>, IoError> {
let panic_handler = PanicHandler::new_in_arc();
let mut config = EventLoopConfig::new();
config.messages_per_tick(1024);
let mut event_loop = EventLoop::configured(config).expect("Error creating event loop");
let channel = event_loop.channel();
let mut event_loop = EventLoop::configured(config).expect("Error creating event loop");
let channel = event_loop.channel();
let panic = panic_handler.clone();
let thread = thread::spawn(move || {
IoManager::<Message>::start(&mut event_loop).unwrap();
let p = panic.clone();
panic.catch_panic(move || {
IoManager::<Message>::start(p, &mut event_loop).unwrap();
}).unwrap()
});
Ok(IoService {
panic_handler: panic_handler,
thread: Some(thread),
host_channel: channel
})
Expand Down
9 changes: 7 additions & 2 deletions util/io/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
use crossbeam::sync::chase_lev;
use service::{HandlerId, IoChannel, IoContext};
use IoHandler;
use panics::*;

use std::sync::{Condvar as SCondvar, Mutex as SMutex};

Expand Down Expand Up @@ -55,6 +56,7 @@ impl Worker {
channel: IoChannel<Message>,
wait: Arc<SCondvar>,
wait_mutex: Arc<SMutex<()>>,
panic_handler: Arc<PanicHandler>
) -> Worker
where Message: Send + Sync + Clone + 'static {
let deleting = Arc::new(AtomicBool::new(false));
Expand All @@ -66,8 +68,11 @@ impl Worker {
};
worker.thread = Some(thread::Builder::new().name(format!("IO Worker #{}", index)).spawn(
move || {
Worker::work_loop(stealer, channel.clone(), wait, wait_mutex.clone(), deleting)
}).expect("Error creating worker thread"));
panic_handler.catch_panic(move || {
Worker::work_loop(stealer, channel.clone(), wait, wait_mutex.clone(), deleting)
}).unwrap()
})
.expect("Error creating worker thread"));
worker
}

Expand Down
2 changes: 1 addition & 1 deletion util/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use util::panics::*;
use {NetworkProtocolHandler, NetworkConfiguration, NonReservedPeerMode};
use error::NetworkError;
use host::{Host, NetworkContext, NetworkIoMessage, ProtocolId};
Expand Down Expand Up @@ -58,6 +57,7 @@ impl NetworkService {
let host_handler = Arc::new(HostHandler { public_url: RwLock::new(None) });
let panic_handler = PanicHandler::new_in_arc();
let io_service = try!(IoService::<NetworkIoMessage>::start());
panic_handler.forward_from(&io_service);

let stats = Arc::new(NetworkStats::new());
let host_info = Host::client_version();
Expand Down
1 change: 0 additions & 1 deletion util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ pub mod nibblevec;
mod heapsizeof;
pub mod semantic_version;
pub mod log;
pub mod panics;
pub mod path;
pub mod snappy;
mod timer;
Expand Down

0 comments on commit 7634f11

Please sign in to comment.