Skip to content

Commit

Permalink
premature exit bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Oct 11, 2024
1 parent c9f1d9f commit e0386e4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ DKN_P2P_LISTEN_ADDR=/ip4/0.0.0.0/tcp/4001
DKN_RELAY_NODES=
# Comma-separated static bootstrap nodes
DKN_BOOTSTRAP_NODES=

## DRIA (profiling only, do not uncomment) ##
# Set to a number of seconds to wait before exiting, only use in profiling build!
# Otherwise, leave this empty.
DKN_EXIT_TIMEOUT=
# DKN_EXIT_TIMEOUT=

## Open AI (if used, required) ##
OPENAI_API_KEY=
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default-members = ["compute"]

[workspace.package]
edition = "2021"
version = "0.2.13"
version = "0.2.14"
license = "Apache-2.0"
readme = "README.md"

Expand Down
7 changes: 5 additions & 2 deletions compute/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ async fn main() -> Result<()> {
let token = CancellationToken::new();
let cancellation_token = token.clone();
tokio::spawn(async move {
if let Ok(timeout_str) = env::var("DKN_EXIT_TIMEOUT").map(|s| s.trim().to_string()) {
let duration_secs = timeout_str.parse().unwrap_or(120);
if let Ok(Ok(duration_secs)) =
env::var("DKN_EXIT_TIMEOUT").map(|s| s.to_string().parse::<u64>())
{
log::warn!("Waiting for {} seconds before exiting.", duration_secs);
tokio::time::sleep(tokio::time::Duration::from_secs(duration_secs)).await;

log::warn!("Exiting due to DKN_EXIT_TIMEOUT.");
cancellation_token.cancel();
} else if let Err(err) = wait_for_termination(cancellation_token.clone()).await {
log::error!("Error waiting for termination: {:?}", err);
Expand Down

0 comments on commit e0386e4

Please sign in to comment.