Skip to content

Commit

Permalink
Agent: Add 10s timeout for requests
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jan 3, 2024
1 parent c2ec00b commit 6fdead9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion p11nethsm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ slots:
danger_insecure_cert: true
# sha256_fingerprints:
# - "31:92:8E:A4:5E:16:5C:A7:33:44:E8:E9:8E:64:C4:AE:7B:2A:57:E5:77:43:49:F3:69:C9:8F:C4:2F:3A:3B:6E"

# timeout: 10
2 changes: 2 additions & 0 deletions pkcs11/src/config/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ pub struct SlotConfig {
pub administrator: Option<UserConfig>,
pub description: Option<String>,
pub instances: Vec<InstanceConfig>,
#[serde(default)]
pub timeout: Option<u64>,
}

// An user
Expand Down
16 changes: 12 additions & 4 deletions pkcs11/src/config/initialization.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::sync::{Arc, Mutex};
use std::{
sync::{Arc, Mutex},
time::Duration,
};

use super::{
config_file::SlotConfig,
Expand Down Expand Up @@ -117,11 +120,16 @@ fn slot_from_config(slot: &SlotConfig) -> Result<Slot, InitializationError> {
tls_conf.with_root_certificates(roots).with_no_client_auth()
};

let agent = ureq::AgentBuilder::new()
let mut builder = ureq::AgentBuilder::new()
.tls_config(Arc::new(tls_conf))
.max_idle_connections(2)
.max_idle_connections_per_host(2)
.build();
.max_idle_connections_per_host(2);

if let Some(t) = slot.timeout {
builder = builder.timeout(Duration::from_secs(t));
}

let agent = builder.build();

let api_config = nethsm_sdk_rs::apis::configuration::Configuration {
client: agent,
Expand Down

0 comments on commit 6fdead9

Please sign in to comment.