Skip to content

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

Merged
shamardy merged 8 commits intodevfrom
graceful-shutdown-on-ctrl-c
Sep 19, 2024
Merged

feat(core): handling CTRL-C signal with graceful shutdown#2213
shamardy merged 8 commits intodevfrom
graceful-shutdown-on-ctrl-c

Conversation

@onur-ozkan
Copy link
Copy Markdown

@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.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
@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 <work@onurozkan.dev>
@onur-ozkan onur-ozkan force-pushed the graceful-shutdown-on-ctrl-c branch from e7d03ad to ae8d70e Compare September 10, 2024 10:34
mariocynicys

This comment was marked as duplicate.

mariocynicys
mariocynicys previously approved these changes Sep 16, 2024
Copy link
Copy Markdown
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!

ctx.stop().await.expect("Couldn't stop the KDF runtime.");
};

// Please note we shouldn't use `MmCtx::spawner` to spawn this future,
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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...

ctx.stop().await.expect("Couldn't stop the KDF runtime.");
};

// Please note we shouldn't use `MmCtx::spawner` to spawn this future,
Copy link
Copy Markdown
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
Copy Markdown
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.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
mariocynicys
mariocynicys previously approved these changes Sep 16, 2024
Copy link
Copy Markdown
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.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
@shamardy shamardy merged commit baa72a7 into dev Sep 19, 2024
@shamardy shamardy deleted the graceful-shutdown-on-ctrl-c branch September 19, 2024 01:35
dimxy pushed 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 pushed 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 pushed 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants