Skip to content

Commit 1a7182c

Browse files
authored
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
1 parent ddf15fe commit 1a7182c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/DDTrace/Integrations/Curl/CurlIntegration.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@ public function init(): int
121121
list($ch, $requestSpan) = $requestSpan;
122122
$requestSpan->metrics["_dd.measured"] = 1;
123123
$info = curl_getinfo($ch);
124-
if (isset($requestSpan->meta['network.destination.name']) && $requestSpan->meta['network.destination.name'] !== 'unparsable-host') {
124+
if (empty($info["http_code"])) {
125+
$saveSpans = true;
126+
}
127+
128+
if (isset($requestSpan->meta[Tag::NETWORK_DESTINATION_NAME]) && $requestSpan->meta[Tag::NETWORK_DESTINATION_NAME] !== 'unparsable-host') {
125129
continue;
126130
}
127131

128132
if (empty($info["http_code"])) {
129-
$saveSpans = true;
130133
if (!isset($error_trace)) {
131134
$error_trace = \DDTrace\get_sanitized_exception_trace(new \Exception(), 1);
132135
}
@@ -183,16 +186,15 @@ public function init(): int
183186
}
184187

185188
list(, $spans) = $data;
189+
if (empty($spans)) {
190+
return;
191+
}
186192

187193
if (!isset($hook->returned["result"]) || $hook->returned["result"] == CURLE_OK) {
188-
if (empty($spans)) {
189-
return;
190-
}
191-
192194
foreach ($spans as $requestSpan) {
193195
list($ch, $requestSpan) = $requestSpan;
194196
if ($ch === $handle) {
195-
if (isset($requestSpan->meta['network.destination.name']) && $requestSpan->meta['network.destination.name'] !== 'unparsable-host') {
197+
if (isset($requestSpan->meta[Tag::NETWORK_DESTINATION_NAME]) && $requestSpan->meta[Tag::NETWORK_DESTINATION_NAME] !== 'unparsable-host') {
196198
continue;
197199
}
198200
$info = curl_getinfo($ch);

0 commit comments

Comments
 (0)