Skip to content

fix bad SIGINT patterns - #689

Merged
plebhash merged 3 commits into
stratum-mining:mainfrom
plebhash:2026-08-05-noise-connection-ctrl-c
Aug 10, 2026
Merged

fix bad SIGINT patterns#689
plebhash merged 3 commits into
stratum-mining:mainfrom
plebhash:2026-08-05-noise-connection-ctrl-c

Conversation

@plebhash

@plebhash plebhash commented Aug 5, 2026

Copy link
Copy Markdown
Member

close #688

@plebhash

plebhash commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

the scope of this PR (more specifically the top commit, currently hashed as fc3cfc0) overlaps with:

but let's see what gets merged first, and then rebase accordingly... no strong opinions on the specific order

@bit-aloo

This comment was marked as resolved.

@bit-aloo bit-aloo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes makes sense. Some suggestions and questions.

Comment thread integration-tests/lib/mining_device/mod.rs
Comment thread integration-tests/lib/sv1_sniffer.rs
Comment thread integration-tests/lib/sv1_sniffer.rs
Comment thread integration-tests/lib/utils.rs
Comment thread stratum-apps/src/lib.rs
@plebhash
plebhash force-pushed the 2026-08-05-noise-connection-ctrl-c branch from fc3cfc0 to 3c7f7ae Compare August 7, 2026 20:27
@bit-aloo

This comment was marked as resolved.

@bit-aloo bit-aloo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

…onnection

`Connection::spawn_reader` and `Connection::spawn_writer` both selected on
`tokio::signal::ctrl_c()` as their shutdown arm. The first poll of either
future makes tokio install a process-global SIGINT handler, so from that
point on SIGINT no longer terminates the process, it only completes those
two futures. Any binary opening a single noise Connection silently lost
default Ctrl+C behavior, and could not be interrupted if it later hung.

Signal handling belongs to the application, not to a transport helper.
Replace both arms with a caller-supplied CancellationToken, mirroring the
sibling helper `ConnectionSV1::new`.

`tokio_util` is re-exported from the crate root so consumers can build the
token without declaring their own dependency on it.

Note this is a breaking change to `Connection::new`.
The sniffers selected on `tokio::signal::ctrl_c()` in arms that do nothing.
Their only real effect was installing a process-global SIGINT handler, which
stops SIGINT from terminating the test binary.

Drop those arms so the sniffers no longer claim the signal. In
`wait_for_message` and `wait_for_keepalive_notify` this leaves a single-arm
`select!`, so the remaining block is awaited directly.

Note this is not sufficient on its own to make Ctrl+C kill a hung test: any
test that starts a role in-process still installs that role's own SIGINT
handler (e.g. `pool_runtime::wait_for_shutdown`), which is correct behavior
for the role binaries but leaks into the test process.
…ries

`PoolRuntime::wait_for_shutdown`, `TranslatorSv2::start` and
`JobDeclaratorClient::start` each selected on `tokio::signal::ctrl_c()`. That
made the libraries install a process-global SIGINT handler, so any process
embedding a role lost default Ctrl+C behavior: in the integration tests, a
SIGINT would gracefully stop the role but leave the test harness running,
making a hung test impossible to interrupt.

All three run loops already break on their own CancellationToken, and all
three types expose `shutdown()`, so the ctrl_c arms are removed and each
binary now watches for the signal itself and calls `shutdown()`.

Behavior of the binaries is unchanged: Ctrl+C still triggers the same
graceful shutdown path, it is just initiated by the binary rather than by
the library.
@plebhash
plebhash force-pushed the 2026-08-05-noise-connection-ctrl-c branch from 3c7f7ae to 7992938 Compare August 10, 2026 15:48
@plebhash
plebhash merged commit d7f280c into stratum-mining:main Aug 10, 2026
10 checks passed
@plebhash
plebhash deleted the 2026-08-05-noise-connection-ctrl-c branch August 10, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

noise_connection installs a process-wide SIGINT handler, breaking Ctrl+C for every consumer

2 participants