Skip to content

Commit 0313f70

Browse files
authored
[nexus] Create a longer-lived connection from Nexus -> Sled Agent (#8149)
Fixes #8144
1 parent d24ba55 commit 0313f70

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

nexus/networking/src/sled_client.rs

+27-7
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,49 @@ pub fn sled_lookup<'a>(
2525
Ok(sled)
2626
}
2727

28+
pub fn default_reqwest_client_builder() -> reqwest::ClientBuilder {
29+
let dur = std::time::Duration::from_secs(60);
30+
reqwest::ClientBuilder::new().connect_timeout(dur).timeout(dur)
31+
}
32+
2833
pub async fn sled_client(
2934
datastore: &DataStore,
3035
lookup_opctx: &OpContext,
3136
sled_id: Uuid,
3237
log: &Logger,
38+
) -> Result<SledAgentClient, Error> {
39+
let client = default_reqwest_client_builder().build().unwrap();
40+
sled_client_ext(datastore, lookup_opctx, sled_id, log, client).await
41+
}
42+
43+
pub async fn sled_client_ext(
44+
datastore: &DataStore,
45+
lookup_opctx: &OpContext,
46+
sled_id: Uuid,
47+
log: &Logger,
48+
client: reqwest::Client,
3349
) -> Result<SledAgentClient, Error> {
3450
let (.., sled) =
3551
sled_lookup(datastore, lookup_opctx, sled_id)?.fetch().await?;
3652

37-
Ok(sled_client_from_address(sled_id, sled.address(), log))
53+
Ok(sled_client_from_address_ext(sled_id, sled.address(), log, client))
3854
}
3955

4056
pub fn sled_client_from_address(
4157
sled_id: Uuid,
4258
address: SocketAddrV6,
4359
log: &Logger,
60+
) -> SledAgentClient {
61+
let client = default_reqwest_client_builder().build().unwrap();
62+
sled_client_from_address_ext(sled_id, address, log, client)
63+
}
64+
65+
pub fn sled_client_from_address_ext(
66+
sled_id: Uuid,
67+
address: SocketAddrV6,
68+
log: &Logger,
69+
client: reqwest::Client,
4470
) -> SledAgentClient {
4571
let log = log.new(o!("SledAgent" => sled_id.to_string()));
46-
let dur = std::time::Duration::from_secs(60);
47-
let client = reqwest::ClientBuilder::new()
48-
.connect_timeout(dur)
49-
.timeout(dur)
50-
.build()
51-
.unwrap();
5272
SledAgentClient::new_with_client(&format!("http://{address}"), client, log)
5373
}

nexus/src/app/sled.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ impl super::Nexus {
147147
pub async fn sled_client(
148148
&self,
149149
id: &SledUuid,
150+
) -> Result<Arc<SledAgentClient>, Error> {
151+
let client =
152+
nexus_networking::default_reqwest_client_builder().build().unwrap();
153+
self.sled_client_ext(id, client).await
154+
}
155+
156+
pub async fn sled_client_ext(
157+
&self,
158+
id: &SledUuid,
159+
client: reqwest::Client,
150160
) -> Result<Arc<SledAgentClient>, Error> {
151161
// TODO: We should consider injecting connection pooling here,
152162
// but for now, connections to sled agents are constructed
@@ -155,11 +165,12 @@ impl super::Nexus {
155165
// Frankly, returning an "Arc" here without a connection pool is a
156166
// little silly; it's not actually used if each client connection exists
157167
// as a one-shot.
158-
let client = nexus_networking::sled_client(
168+
let client = nexus_networking::sled_client_ext(
159169
&self.db_datastore,
160170
&self.opctx_alloc,
161171
id.into_untyped_uuid(),
162172
&self.log,
173+
client,
163174
)
164175
.await?;
165176
Ok(Arc::new(client))

nexus/src/app/support_bundles.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,20 @@ impl super::Nexus {
9090
.db_datastore
9191
.zpool_get_sled_if_in_service(&opctx, bundle.zpool_id.into())
9292
.await?;
93-
let client = self.sled_client(&sled_id).await?;
93+
94+
let short_timeout = std::time::Duration::from_secs(60);
95+
let long_timeout = std::time::Duration::from_secs(3600);
96+
let client = nexus_networking::default_reqwest_client_builder()
97+
// Continuing to read from the sled agent should happen relatively
98+
// quickly.
99+
.read_timeout(short_timeout)
100+
// However, the bundle itself may be large. As long as we're
101+
// continuing to make progress (see: read_timeout) we should be
102+
// willing to keep transferring the bundle for a while longer.
103+
.timeout(long_timeout)
104+
.build()
105+
.expect("Failed to build reqwest Client");
106+
let client = self.sled_client_ext(&sled_id, client).await?;
94107

95108
// TODO: Use "range"?
96109

0 commit comments

Comments
 (0)