Skip to content

Commit 7062e43

Browse files
committed
Drop connection after usage
1 parent 2d97b6a commit 7062e43

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

mullvad-api/src/rest.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ pub enum Error {
5050
#[error("Hyper error")]
5151
HyperError(#[from] Arc<hyper::Error>),
5252

53+
/// Connection dropped
54+
#[error("Connection dropped unexpectedly")]
55+
ConnectionDropped,
56+
5357
#[error("Invalid header value")]
5458
InvalidHeaderError,
5559

@@ -457,14 +461,18 @@ where
457461

458462
let (mut sender, conn) = hyper::client::conn::http1::handshake(tokio_io).await?;
459463

460-
tokio::task::spawn(async move {
461-
if let Err(err) = conn.await {
462-
println!("Connection failed: {:?}", err);
464+
let response = tokio::select! {
465+
res = sender.send_request(self.request) => res.map_err(Error::from),
466+
conn_res = conn => {
467+
log::error!("API request connection failed");
468+
match conn_res {
469+
Ok(()) => Err(Error::ConnectionDropped),
470+
Err(err) => Err(Error::HyperError(Arc::new(err))),
471+
}
463472
}
464-
});
473+
};
465474

466475
// Make request to hyper client
467-
let response = sender.send_request(self.request).await.map_err(Error::from);
468476

469477
// Notify access token store of expired tokens
470478
if let (Some(account), Some(store)) = (&self.account, &self.access_token_store) {

0 commit comments

Comments
 (0)