Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): handling CTRL-C signal with graceful shutdown #2213

Merged
merged 8 commits into from
Sep 19, 2024

Conversation

onur-ozkan
Copy link
Member

@onur-ozkan onur-ozkan commented Sep 10, 2024

Closes #2145

To Test: cc @KomodoPlatform/qa
For testing on Windows and MacOS. Try CTRL-C on terminal for a running mm2 instance, it should work the same as using stop RPC.

@onur-ozkan onur-ozkan added enhancement New feature or request under review labels Sep 10, 2024
@onur-ozkan onur-ozkan changed the title feat(core): handling CTRL-C signals with graceful shutdowns feat(core): handling CTRL-C signal with graceful shutdown Sep 10, 2024
Signed-off-by: onur-ozkan <[email protected]>
mariocynicys

This comment was marked as duplicate.

mariocynicys
mariocynicys previously approved these changes Sep 16, 2024
Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

LGTM!

if let Err(e) = ctx.stop() {
error!("Error stopping MmCtx: {}", e);
}
ctx.stop().await.expect("Couldn't stop the KDF runtime.");
};

// Please note we shouldn't use `MmCtx::spawner` to spawn this future,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this is not really an issue here since the aborting code is in the last sync code block inside stop() so we won't yield back the execution to the runtime and thus won't die before we should.
We should be fine running the future inside the ctx spawner.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if it's a good idea to spawn a future inside the future pool to clear the pool. Haven't checked that in detail but it may cause the future to deconstruct itself before it finishes. It's better to not touch that part and keep this PR as simple as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that, this isn't just about native threads, there is the JS runtime too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. It's not much of a difference and safer this way in case someone adds some awaited call after the abortion code.

We might as well then change...

if let Err(e) = ctx.stop() {
error!("Error stopping MmCtx: {}", e);
}
ctx.stop().await.expect("Couldn't stop the KDF runtime.");
};

// Please note we shouldn't use `MmCtx::spawner` to spawn this future,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. It's not much of a difference and safer this way in case someone adds some awaited call after the abortion code.

We might as well then change...

/// It's important to spawn this task as soon as `Ctx` is in the correct state.
#[cfg(not(target_arch = "wasm32"))]
fn spawn_ctrl_c_handler(ctx: mm2_core::mm_ctx::MmArc) {
ctx.spawner().spawn(async move {
Copy link
Collaborator

Choose a reason for hiding this comment

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

...this to not use the ctx spawner and call stop inside.

Let's use the global spawner here.

mariocynicys
mariocynicys previously approved these changes Sep 16, 2024
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I have a few comments.

mm2src/mm2_main/src/mm2.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/mm2.rs Show resolved Hide resolved
Signed-off-by: onur-ozkan <[email protected]>
Cargo.toml Outdated Show resolved Hide resolved
Signed-off-by: onur-ozkan <[email protected]>
@shamardy shamardy merged commit baa72a7 into dev Sep 19, 2024
24 of 28 checks passed
@shamardy shamardy deleted the graceful-shutdown-on-ctrl-c branch September 19, 2024 01:35
dimxy added a commit that referenced this pull request Oct 4, 2024
* dev:
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
dimxy added a commit that referenced this pull request Oct 4, 2024
* dev:
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
dimxy added a commit that referenced this pull request Oct 17, 2024
* dev:
  fix(cosmos): fix tx broadcasting error (#2238)
  chore(solana): remove solana implementation (#2239)
  chore(cli): remove leftover subcommands from help message (#2235)
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants