Skip to content

network/onion: detect Tor liveness via socket close instead of polling #5161

@eval-exec

Description

@eval-exec

Feature Request

Is your feature request related to a problem? Please describe.

OnionService polls GETINFO uptime every 3 seconds to check if Tor is alive (

self.handle.spawn(async move {
let mut ticker = tokio::time::interval(tokio::time::Duration::from_secs(3));
loop {
tokio::select! {
_ = ticker.tick() => {
let uptime = tor_controller.get_uptime().await;
if let Err(err) = uptime {
error!("Failed to get tor server uptime: {:?}", err);
drop(tor_server_alive_tx);
return;
}
}
_ = stop_rx.cancelled() => {
info!("OnionService received stop signal, exiting...");
drop(tor_server_alive_tx);
return;
}
}
}
});
). This wastes control-port traffic and adds a 3-second blind window before CKB notices Tor is gone.

Describe the solution you'd like

React to the control-connection close instead of polling — either by detecting when the TcpStream closes, or by subscribing to SETEVENTS STATUS_CLIENT.

For reference, Bitcoin Core uses a libevent BEV_EVENT_EOF callback to detect the close instantly and then triggers a reconnect handler:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions