From 1a7182ce5f844d39cd203191bc2d0d5e07870405 Mon Sep 17 00:00:00 2001 From: Luc Vieillescazes Date: Thu, 12 Sep 2024 16:26:54 +0200 Subject: [PATCH] Fix a race condition where curl_multi_exec is called many times while finished ($still_running at false) (#2847) before curl_multi_info_read. In that case, the spans could have been removed from the storage --- .../Integrations/Curl/CurlIntegration.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/DDTrace/Integrations/Curl/CurlIntegration.php b/src/DDTrace/Integrations/Curl/CurlIntegration.php index 623c41f1d1..61304f8d29 100644 --- a/src/DDTrace/Integrations/Curl/CurlIntegration.php +++ b/src/DDTrace/Integrations/Curl/CurlIntegration.php @@ -121,12 +121,15 @@ public function init(): int list($ch, $requestSpan) = $requestSpan; $requestSpan->metrics["_dd.measured"] = 1; $info = curl_getinfo($ch); - if (isset($requestSpan->meta['network.destination.name']) && $requestSpan->meta['network.destination.name'] !== 'unparsable-host') { + if (empty($info["http_code"])) { + $saveSpans = true; + } + + if (isset($requestSpan->meta[Tag::NETWORK_DESTINATION_NAME]) && $requestSpan->meta[Tag::NETWORK_DESTINATION_NAME] !== 'unparsable-host') { continue; } if (empty($info["http_code"])) { - $saveSpans = true; if (!isset($error_trace)) { $error_trace = \DDTrace\get_sanitized_exception_trace(new \Exception(), 1); } @@ -183,16 +186,15 @@ public function init(): int } list(, $spans) = $data; + if (empty($spans)) { + return; + } if (!isset($hook->returned["result"]) || $hook->returned["result"] == CURLE_OK) { - if (empty($spans)) { - return; - } - foreach ($spans as $requestSpan) { list($ch, $requestSpan) = $requestSpan; if ($ch === $handle) { - if (isset($requestSpan->meta['network.destination.name']) && $requestSpan->meta['network.destination.name'] !== 'unparsable-host') { + if (isset($requestSpan->meta[Tag::NETWORK_DESTINATION_NAME]) && $requestSpan->meta[Tag::NETWORK_DESTINATION_NAME] !== 'unparsable-host') { continue; } $info = curl_getinfo($ch);