-
Notifications
You must be signed in to change notification settings - Fork 118
feat(core): handling CTRL-C signal with graceful shutdown #2213
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
Changes from 3 commits
7cc5157
07b9a6d
ae8d70e
f86dd5c
7d0f619
dc26779
a3791bd
a2643f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ | |
|
|
||
| use coins::{lp_coinfind, lp_coinfind_any, lp_coininit, CoinsContext, MmCoinEnum}; | ||
| use common::executor::Timer; | ||
| use common::log::error; | ||
| use common::{rpc_err_response, rpc_response, HyRes}; | ||
| use futures::compat::Future01CompatExt; | ||
| use http::Response; | ||
|
|
@@ -242,29 +241,13 @@ pub async fn my_balance(ctx: MmArc, req: Json) -> Result<Response<Vec<u8>>, Stri | |
| Ok(try_s!(Response::builder().body(res))) | ||
| } | ||
|
|
||
| #[cfg(not(target_arch = "wasm32"))] | ||
| async fn close_async_connection(ctx: &MmArc) { | ||
| if let Some(async_conn) = ctx.async_sqlite_connection.as_option() { | ||
| let mut conn = async_conn.lock().await; | ||
| if let Err(e) = conn.close().await { | ||
| error!("Error stopping AsyncConnection: {}", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub async fn stop(ctx: MmArc) -> Result<Response<Vec<u8>>, String> { | ||
| dispatch_lp_event(ctx.clone(), StopCtxEvent.into()).await; | ||
| // Should delay the shutdown a bit in order not to trip the "stop" RPC call in unit tests. | ||
| // Stopping immediately leads to the "stop" RPC call failing with the "errno 10054" sometimes. | ||
| let fut = async move { | ||
| Timer::sleep(0.05).await; | ||
|
|
||
| #[cfg(not(target_arch = "wasm32"))] | ||
| close_async_connection(&ctx).await; | ||
|
|
||
| if let Err(e) = ctx.stop() { | ||
| error!("Error stopping MmCtx: {}", e); | ||
| } | ||
| ctx.stop().await.expect("Couldn't stop the KDF runtime."); | ||
|
shamardy marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| // Please note we shouldn't use `MmCtx::spawner` to spawn this future, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 We might as well then change... |
||
|
|
||
There was a problem hiding this comment.
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
stopinside.Let's use the global spawner here.