Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class S3 extends Device

protected static int $retryDelay = 500;

protected static ?\CurlShareHandle $curlShare = null;

protected array $headers = [
'host' => '',
'date' => '',
Expand Down Expand Up @@ -731,7 +733,15 @@ protected function call(string $operation, string $method, string $uri, string $
$response->headers = [];

// Basic setup
if (self::$curlShare === null) {
self::$curlShare = curl_share_init();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Failed Share Init Crashes

If curl_share_init() returns false, this assignment writes a boolean into a ?\CurlShareHandle static property before the existing S3 error handling can run. That turns a curl setup failure into a PHP TypeError for the request instead of a controlled storage error or a fallback to an unshared handle.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Storage/Device/S3.php
Line: 737

Comment:
**Failed Share Init Crashes**

If `curl_share_init()` returns `false`, this assignment writes a boolean into a `?\CurlShareHandle` static property before the existing S3 error handling can run. That turns a curl setup failure into a PHP `TypeError` for the request instead of a controlled storage error or a fallback to an unshared handle.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

curl_share_setopt(self::$curlShare, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
curl_share_setopt(self::$curlShare, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
curl_share_setopt(self::$curlShare, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Shared Connection Cache Races

When Swoole runs overlapping S3 operations, each coroutine creates its own easy handle but now points it at the same process-wide connection cache. libcurl does not support sharing CURL_LOCK_DATA_CONNECT across concurrent transfers, so concurrent curl_exec() calls can intermittently fail or reuse connection state incorrectly under the workload this change targets.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Storage/Device/S3.php
Line: 740

Comment:
**Shared Connection Cache Races**

When Swoole runs overlapping S3 operations, each coroutine creates its own easy handle but now points it at the same process-wide connection cache. libcurl does not support sharing `CURL_LOCK_DATA_CONNECT` across concurrent transfers, so concurrent `curl_exec()` calls can intermittently fail or reuse connection state incorrectly under the workload this change targets.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

}

$curl = curl_init();
curl_setopt($curl, CURLOPT_SHARE, self::$curlShare);
curl_setopt($curl, CURLOPT_USERAGENT, 'utopia-php/storage');
curl_setopt($curl, CURLOPT_URL, $url);

Expand Down