2424use Symfony \Component \HttpClient \Exception \TransportException ;
2525use Symfony \Component \HttpClient \HttpClientTrait ;
2626use Symfony \Component \HttpClient \Internal \AmpBody ;
27+ use Symfony \Component \HttpClient \Internal \AmpCanary ;
2728use Symfony \Component \HttpClient \Internal \AmpClientState ;
2829use Symfony \Component \HttpClient \Internal \ClientState ;
2930use Symfony \Contracts \HttpClient \ResponseInterface ;
@@ -108,13 +109,17 @@ public function __destruct()
108109 try {
109110 $ this ->doDestruct ();
110111 } finally {
112+ $ multi = clone $ this ->multi ;
113+
111114 $ this ->close ();
112115
113116 // Clear the DNS cache when all requests completed
114117 if (0 >= --$ this ->multi ->responseCount ) {
115118 $ this ->multi ->responseCount = 0 ;
116119 $ this ->multi ->dnsCache = [];
117120 }
121+
122+ $ this ->multi = $ multi ;
118123 }
119124 }
120125
@@ -189,11 +194,9 @@ private static function select(ClientState $multi, float $timeout): int
189194
190195 private static function generateResponse (Request $ request , AmpClientState $ multi , string $ id , array &$ info , array &$ headers , CancellationTokenSource $ canceller , array &$ options , \Closure $ onProgress , &$ handle , ?LoggerInterface $ logger )
191196 {
192- $ activity = &$ multi ->handlesActivity ;
193-
194- $ request ->setInformationalResponseHandler (static function (Response $ response ) use (&$ activity , $ id , &$ info , &$ headers ) {
197+ $ request ->setInformationalResponseHandler (static function (Response $ response ) use ($ multi , $ id , &$ info , &$ headers ) {
195198 self ::addResponseHeaders ($ response , $ info , $ headers );
196- $ activity [$ id ][] = new InformationalChunk ($ response ->getStatus (), $ response ->getHeaders ());
199+ $ multi -> handlesActivity [$ id ][] = new InformationalChunk ($ response ->getStatus (), $ response ->getHeaders ());
197200 self ::stopLoop ();
198201 });
199202
@@ -207,11 +210,11 @@ private static function generateResponse(Request $request, AmpClientState $multi
207210
208211 $ options = null ;
209212
210- $ activity [$ id ][] = new FirstChunk ();
213+ $ multi -> handlesActivity [$ id ][] = new FirstChunk ();
211214
212215 if ('HEAD ' === $ response ->getRequest ()->getMethod () || \in_array ($ info ['http_code ' ], [204 , 304 ], true )) {
213- $ activity [$ id ][] = null ;
214- $ activity [$ id ][] = null ;
216+ $ multi -> handlesActivity [$ id ][] = null ;
217+ $ multi -> handlesActivity [$ id ][] = null ;
215218 self ::stopLoop ();
216219
217220 return ;
@@ -231,14 +234,14 @@ private static function generateResponse(Request $request, AmpClientState $multi
231234 }
232235
233236 $ info ['size_download ' ] += \strlen ($ data );
234- $ activity [$ id ][] = $ data ;
237+ $ multi -> handlesActivity [$ id ][] = $ data ;
235238 }
236239
237- $ activity [$ id ][] = null ;
238- $ activity [$ id ][] = null ;
240+ $ multi -> handlesActivity [$ id ][] = null ;
241+ $ multi -> handlesActivity [$ id ][] = null ;
239242 } catch (\Throwable $ e ) {
240- $ activity [$ id ][] = null ;
241- $ activity [$ id ][] = $ e ;
243+ $ multi -> handlesActivity [$ id ][] = null ;
244+ $ multi -> handlesActivity [$ id ][] = $ e ;
242245 } finally {
243246 $ info ['download_content_length ' ] = $ info ['size_download ' ];
244247 }
0 commit comments