Skip to content

Commit

Permalink
Fix a race condition where curl_multi_exec is called many times while…
Browse files Browse the repository at this point in the history
… finished ($still_running at false) (#2847)

before curl_multi_info_read.
In that case, the spans could have been removed from the storage
  • Loading branch information
iamluc authored Sep 12, 2024
1 parent ddf15fe commit 1a7182c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/DDTrace/Integrations/Curl/CurlIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1a7182c

Please sign in to comment.