Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ tempfile = "3.0"

[profile.release]
lto = true
panic = 'abort'
panic = 'unwind'
codegen-units = 1

[patch.crates-io.electrum-client]
Expand Down
24 changes: 23 additions & 1 deletion src/electrum/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::net::IpAddr;
use std::net::{Shutdown, SocketAddr, TcpListener, TcpStream};
use std::os::unix::fs::FileTypeExt;
use std::os::unix::net::{UnixListener, UnixStream};
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::path::Path;
use std::sync::atomic::AtomicBool;
use std::sync::mpsc::{Receiver, Sender};
Expand Down Expand Up @@ -903,7 +904,28 @@ impl RPC {
discovery,
);
senders.lock().unwrap().push(conn.chan.sender());
conn.run();
// unwind any panics inside the connection for logging
//
// Safety: we use AssertUnwindSafe because we don't have any
// interior mutability that could be left in an invalid state
// after a panic. We just log and exit the thread.
let result = catch_unwind(AssertUnwindSafe(|| {
conn.run();
}));
// panic occurred
if let Err(err) = result {
let msg = if let Some(s) = err.downcast_ref::<&str>() {
*s
} else if let Some(s) = err.downcast_ref::<String>() {
s.as_str()
} else {
"(unknown panic payload)"
};
error!("[{}] connection panicked: {}", addr, msg);
// Forward the panic for now just to keep the behavior similar to before
// (Although panics were silently ignored before, so it's not the same)
std::panic::panic_any(err);
}
info!("[{}] disconnected peer", addr);
let _ = killer_clone.send(());
let _ = garbage_sender.send(std::thread::current().id());
Expand Down
13 changes: 12 additions & 1 deletion start
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ NODENAME=$(hostname|cut -d . -f1)
LOCATION=$(hostname|cut -d . -f2)
USAGE="Usage: $0 (mainnet|testnet|signet|liquid|liquidtestnet) [popular-scripts]"

# set default log verbosity if unset
if [ -z "${ELECTRS_LOG_VERBOSITY+x}" ];then
ELECTRS_LOG_VERBOSITY="-vv"
# validate log verbosity if set
# Can be -v, -vv, -vvv, -vvvv or "" (set to empty string)
elif [[ -n "${ELECTRS_LOG_VERBOSITY}" && ! "${ELECTRS_LOG_VERBOSITY}" =~ ^-v{1,4}$ ]];then
echo "[!] ELECTRS_LOG_VERBOSITY variable is set to invalid value '${ELECTRS_LOG_VERBOSITY}'." >&2
echo "[!] It must be one of: -v, -vv, -vvv, -vvvv or \"\". If unset it will default to -vv." >&2
exit 1
fi

# load rust if necessary
if [ -e "${HOME}/.cargo/env" ];then
source "${HOME}/.cargo/env"
Expand Down Expand Up @@ -229,6 +240,6 @@ do
--address-search \
--utxos-limit "${UTXOS_LIMIT}" \
--electrum-txs-limit "${ELECTRUM_TXS_LIMIT}" \
-vv
"${ELECTRS_LOG_VERBOSITY}"
sleep 1
done