-
Notifications
You must be signed in to change notification settings - Fork 58
perf(s3): share DNS, TLS session and connection cache across requests #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,8 @@ class S3 extends Device | |
|
|
||
| protected static int $retryDelay = 500; | ||
|
|
||
| protected static ?\CurlShareHandle $curlShare = null; | ||
|
|
||
| protected array $headers = [ | ||
| 'host' => '', | ||
| 'date' => '', | ||
|
|
@@ -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(); | ||
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 Prompt To Fix With AIThis 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. |
||
| } | ||
|
|
||
| $curl = curl_init(); | ||
| curl_setopt($curl, CURLOPT_SHARE, self::$curlShare); | ||
| curl_setopt($curl, CURLOPT_USERAGENT, 'utopia-php/storage'); | ||
| curl_setopt($curl, CURLOPT_URL, $url); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
curl_share_init()returnsfalse, this assignment writes a boolean into a?\CurlShareHandlestatic property before the existing S3 error handling can run. That turns a curl setup failure into a PHPTypeErrorfor the request instead of a controlled storage error or a fallback to an unshared handle.Prompt To Fix With AI