@@ -102,8 +102,8 @@ impl HttpClient for H1Client {
102
102
103
103
match scheme {
104
104
"http" => {
105
- let pool = if let Some ( pool ) = self . http_pools . get ( & addr) {
106
- pool
105
+ let pool_ref = if let Some ( pool_ref ) = self . http_pools . get ( & addr) {
106
+ pool_ref
107
107
} else {
108
108
let manager = TcpConnection :: new ( addr) ;
109
109
let pool = Pool :: < TcpStream , std:: io:: Error > :: new (
@@ -113,15 +113,19 @@ impl HttpClient for H1Client {
113
113
self . http_pools . insert ( addr, pool) ;
114
114
self . http_pools . get ( & addr) . unwrap ( )
115
115
} ;
116
- let pool = pool. clone ( ) ;
116
+
117
+ // Deadlocks are prevented by cloning an inner pool Arc and dropping the original locking reference before we await.
118
+ let pool = pool_ref. clone ( ) ;
119
+ std:: mem:: drop ( pool_ref) ;
120
+
117
121
let stream = pool. get ( ) . await ?;
118
122
req. set_peer_addr ( stream. peer_addr ( ) . ok ( ) ) ;
119
123
req. set_local_addr ( stream. local_addr ( ) . ok ( ) ) ;
120
124
client:: connect ( TcpConnWrapper :: new ( stream) , req) . await
121
125
}
122
126
"https" => {
123
- let pool = if let Some ( pool ) = self . https_pools . get ( & addr) {
124
- pool
127
+ let pool_ref = if let Some ( pool_ref ) = self . https_pools . get ( & addr) {
128
+ pool_ref
125
129
} else {
126
130
let manager = TlsConnection :: new ( host. clone ( ) , addr) ;
127
131
let pool = Pool :: < TlsStream < TcpStream > , Error > :: new (
@@ -131,7 +135,11 @@ impl HttpClient for H1Client {
131
135
self . https_pools . insert ( addr, pool) ;
132
136
self . https_pools . get ( & addr) . unwrap ( )
133
137
} ;
134
- let pool = pool. clone ( ) ;
138
+
139
+ // Deadlocks are prevented by cloning an inner pool Arc and dropping the original locking reference before we await.
140
+ let pool = pool_ref. clone ( ) ;
141
+ std:: mem:: drop ( pool_ref) ;
142
+
135
143
let stream = pool
136
144
. get ( )
137
145
. await
0 commit comments