use time::SystemTime instead of time::Instant as the latter may use libc::clock_gettime(CLOCK_MONOTONIC) eg. on android and does not advance while being in deep sleep mode. therefore, time::Instant is not a reliable way for timeouts or stoping times.

This commit is contained in:
B. Petersen
2020-07-13 01:07:05 +02:00
committed by link2xt
parent 6cb75114c1
commit 4b445b7dd7
3 changed files with 11 additions and 7 deletions

View File

@@ -247,7 +247,7 @@ async fn generate_keypair(context: &Context) -> Result<KeyPair> {
secret: SignedSecretKey::from_slice(&sec_bytes)?, secret: SignedSecretKey::from_slice(&sec_bytes)?,
}), }),
Err(sql::Error::Sql(rusqlite::Error::QueryReturnedNoRows)) => { Err(sql::Error::Sql(rusqlite::Error::QueryReturnedNoRows)) => {
let start = std::time::Instant::now(); let start = std::time::SystemTime::now();
let keytype = KeyGenType::from_i32(context.get_config_int(Config::KeyGenType).await) let keytype = KeyGenType::from_i32(context.get_config_int(Config::KeyGenType).await)
.unwrap_or_default(); .unwrap_or_default();
info!(context, "Generating keypair with type {}", keytype); info!(context, "Generating keypair with type {}", keytype);
@@ -258,7 +258,7 @@ async fn generate_keypair(context: &Context) -> Result<KeyPair> {
info!( info!(
context, context,
"Keypair generated in {:.3}s.", "Keypair generated in {:.3}s.",
start.elapsed().as_secs() start.elapsed().unwrap_or_default().as_secs()
); );
Ok(keypair) Ok(keypair)
} }

View File

@@ -2,7 +2,7 @@
pub mod send; pub mod send;
use std::time::{Duration, Instant}; use std::time::{Duration, SystemTime};
use async_smtp::smtp::client::net::*; use async_smtp::smtp::client::net::*;
use async_smtp::*; use async_smtp::*;
@@ -55,7 +55,7 @@ pub(crate) struct Smtp {
/// Timestamp of last successful send/receive network interaction /// Timestamp of last successful send/receive network interaction
/// (eg connect or send succeeded). On initialization and disconnect /// (eg connect or send succeeded). On initialization and disconnect
/// it is set to None. /// it is set to None.
last_success: Option<Instant>, last_success: Option<SystemTime>,
} }
impl Smtp { impl Smtp {
@@ -76,7 +76,11 @@ impl Smtp {
/// have been successfully used the last 60 seconds /// have been successfully used the last 60 seconds
pub async fn has_maybe_stale_connection(&self) -> bool { pub async fn has_maybe_stale_connection(&self) -> bool {
if let Some(last_success) = self.last_success { if let Some(last_success) = self.last_success {
Instant::now().duration_since(last_success).as_secs() > 60 SystemTime::now()
.duration_since(last_success)
.unwrap_or_default()
.as_secs()
> 60
} else { } else {
false false
} }
@@ -188,7 +192,7 @@ impl Smtp {
} }
self.transport = Some(trans); self.transport = Some(trans);
self.last_success = Some(Instant::now()); self.last_success = Some(SystemTime::now());
context.emit_event(Event::SmtpConnected(format!( context.emit_event(Event::SmtpConnected(format!(
"SMTP-LOGIN as {} ok", "SMTP-LOGIN as {} ok",

View File

@@ -53,7 +53,7 @@ impl Smtp {
"Message len={} was smtp-sent to {}", "Message len={} was smtp-sent to {}",
message_len, recipients_display message_len, recipients_display
))); )));
self.last_success = Some(std::time::Instant::now()); self.last_success = Some(std::time::SystemTime::now());
Ok(()) Ok(())
} else { } else {