Skip to content

CI-8: S3 storage HTTP timeouts, retries, redirect guard and no connection reuse - #16

Merged
wtorsi merged 10 commits into
8.1from
ci-8-s3-timeouts
Oct 20, 2026
Merged

wtorsi merged 10 commits into
8.1from
ci-8-s3-timeouts

Conversation

@wtorsi

@wtorsi wtorsi commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CI-8: optional HTTP timeouts and retry policy for S3 storages, and the two client settings that make one SDK attempt one HTTP transfer.

  • R-B1–R-B4: config keys and pass-through. Two optional blocks per storage: http (connect_timeout, timeout: seconds, finite float >= 0.001, D-28) and retries (mode: legacy/standard/adaptive; max_attempts: int >= 1). If a block is set, every subkey is required; a missing, unknown or invalid subkey throws InvalidConfigurationException with the key path. The blocks are passed to S3Client; with http, the client's http argument also gets allow_redirects: false and curl: [CURLOPT_FORBID_REUSE => true] (R-B7, R-B8). The file_system driver accepts and ignores them.
  • D-28: timeout domain. connect_timeout and timeout must be finite and >= 0.001 s: .inf or a value below 0.001 fails configuration processing with an InvalidConfigurationException that names the key path (551a07c). Reason: on such a value Guzzle 7 silently disables the timeout (CURLOPT_TIMEOUT_MS = 0), and Guzzle 8 rejects every request.
  • I-5: identical to 8.1.4 without the keys. An unset block is not passed to the client. Without both blocks the client arguments and the client definition are exactly those of 8.1.4: no allow_redirects, no curl, no configurator.
  • R-B5. S3Storage behaviour is unchanged (exception wrapping, NoSuchKey, SaveAs), except for R-B7 and R-B8. Docs: after a failed download() the target file may hold a partial body or the S3 error XML; the caller deletes it.
  • R-B6. README and CLAUDE.md describe the keys and state that the timeouts bound an operation only with static credentials (the SDK provider chain runs outside them), Guzzle's curl handler and an asynchronous DNS resolver.
  • R-B7: redirect guard (only with http). The client gets allow_redirects: false. S3RedirectGuard adds one step to the init step of the handler list, outside retry and s3.permanent_redirect. The step turns a 3xx result into exactly S3Exception without an AWS error code, so a 3xx never reads as NoSuchKey and is never retried (one HTTP request). A 301 stays PermanentRedirectException.
  • R-B8: CURLOPT_FORBID_REUSE (only with http). The client's http argument gets curl: [CURLOPT_FORBID_REUSE => true]. Every request opens a new TCP (and TLS) connection, so Guzzle never re-sends a request on a dead reused connection, and HTTP requests per operation = SDK attempts.

Timeout tests on a client without http/retries (AC-5, Task 2a)

Recorded red run: the four timeout tests of S3StorageFaultTest against a client without http/retries (the two lines temporarily removed from FakeS3Harness::storage(), then restored). T_test = 0.5 s; the harness kills the operation after 10·T_test.

Test (host) Wall time First failed assertion
testConnectTimeout upload 5.524 s operation exceeded 10·T_test (5.0 s): "upload" killed after 5.001 s. (FakeS3Harness.php:153)
testConnectTimeout download 5.517 s … "download" killed after 5.004 s.
testAcceptedAndSilent upload 5.200 s … "upload" killed after 5.007 s.
testAcceptedAndSilent download 5.204 s … "download" killed after 5.011 s.
testDripFeed upload 5.226 s … "upload" killed after 5.002 s.
testDripFeed download 5.236 s … "download" killed after 5.012 s.
testSingleAttemptDoesNotRetry upload 5.192 s … "upload" killed after 5.003 s.
testSingleAttemptDoesNotRetry download 5.222 s … "download" killed after 5.007 s.

All ≤ 10·T_test + 1 s = 6 s (the connect tests include the 0.5 s probe). Linux container (connect tests only): killed after 5.002 s / 5.003 s. With http/retries all eight pass.

Redirect tests (AC-17–AC-19, Task 3b)

Each test ran against three versions of the code: v1 (http/retries only), v2 (allow_redirects: false only), and with the fix (373db61).

Test (data set) v1: http/retries, no allow_redirects, no guard v2: allow_redirects=false only with fix
AC-17 301+Location, PUT RED: S3Exception instead of PermanentRedirectException; followed to the silent target, NetworkTimeoutException, 2 attempts, 2.08 s GREEN GREEN
AC-17 301+Location, GET RED: same; 2 attempts, 1.58 s GREEN GREEN
AC-18 307+Location, PUT RED: connection error (followed, timeout), 2 attempts, 1.68 s RED: silent success, 1 attempt GREEN
AC-18 307+Location, GET RED: same, 2.57 s RED: silent success GREEN
AC-19 307 no Location, PUT RED: silent success, 1 attempt RED: silent success GREEN
AC-19 307 no Location, GET RED: silent success RED: silent success GREEN
AC-19 302 no Location, PUT RED: silent success RED: silent success GREEN
AC-19 302 no Location, GET RED: silent success RED: silent success GREEN

Keep-alive test (AC-20, Task 4)

Scenario keep_alive: a warm-up download() leaves a kept-alive connection; the server reads the PUT body on it and closes the connection unanswered. Upload of 1 040 000 B, T_test = 0.5 s, A = 2.

Code Requests Connections PUTs SDK attempts upload() time Result
Without R-B8 (373db61 + test), 3 runs 4 3 3 2 2.19–3.35 s RED (PUT reused the warm-up connection, Guzzle re-sent it on a new one, then SDK attempt 2)
With R-B8 (e651a32), 3 runs 3 3 2 2 1.43–1.87 s GREEN (every request on its own connection, PUTs = attempts, within the 4 s bound)

The strict review reproduced it on Linux: 5/5 red without R-B8, 5/5 green with it.

CI: libcurl >= 8.11

The connect-timeout test needs libcurl >= 8.11. Older libcurl words a connect timeout as "Failed to connect … Timeout was reached", which Guzzle classifies as NetworkTimeoutException, not ConnectTimeoutException. The test fails (never skips) on older libcurl. The php.yml job therefore runs in the php:8.5-cli-trixie container (libcurl 8.14), not on the runner's Ubuntu 24.04 (libcurl 8.5). It prints the PHP and libcurl versions in the step "Show PHP and libcurl versions".

Limits

  • Static credentials. Without credentials, the SDK provider chain (env, ini, ECS, IMDS) runs outside these timeouts and retries.
  • ext-curl. A storage with http requires ext-curl: without it, compiling the container fails with Undefined constant "CURLOPT_FORBID_REUSE".
  • stream request option (Guzzle 8+). On Guzzle 8+, requests with stream to the client of a storage with http fail: Guzzle's StreamHandler rejects the curl option (InvalidArgumentException).
  • L-10: redirecting endpoints. An endpoint that redirects (for example a 307 to another host) fails every operation of a storage with http. Check that the endpoint answers without redirects before you set http. A storage without http follows redirects as in 8.1.4.
  • Literal values. %env(float:…)% / %env(int:…)% placeholders fail the >= 0.001 / >= 1 check, because Symfony validates a placeholder with a dummy 0.
  • Timing bound. The timeouts bound one transfer up to a small measured excess over timeout. This PR does not claim a stronger per-operation bound.

CI run on this PR

Run 39319614656 at 551a07c: green. Earlier run 39307052661 at 09e3848: green; the environment below is from that run. PHP 8.5.11, libcurl 8.14.1 (ext-curl loaded). The bundle has no lock file; composer install resolved aws/aws-sdk-php 3.401.3 and guzzlehttp/guzzle 8.3.0. Tests: 203, assertions: 612; PHPStan: no errors; PHP-CS-Fixer: 0 of 71 files to fix.

Merging this PR, the release PR 8.1 → main and the v8.1.5 tag are separate owner decisions.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm

Dev and others added 10 commits October 19, 2026 14:18
…ge (CI-8 Task 1)

Storages accept two optional blocks, http {connect_timeout, timeout: float > 0}
and retries {mode: legacy|standard|adaptive, max_attempts: int >= 1}. If a
block is set, every subkey is required; a missing, unknown or invalid subkey
fails configuration processing with the key path (R-B1, D-9). Integer literals
are accepted and cast to float.

An s3 storage passes a set block to the S3Client arguments as http /
retries, after the 8.1.4 keys; an unset block stays absent, so without both
blocks the client definition equals 8.1.4 (R-B2, R-B3). The file_system
driver accepts and ignores both blocks, including an s3 base merged with a
file_system override (R-B4).

README: option rows (also the missing path_style and credentials rows) and
an S3 timeouts section with the limits of the bound (static credentials,
curl handler, asynchronous DNS). CLAUDE.md: Service Configuration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
…p feed and single attempt (CI-8 Task 2a)

A fake TCP server and the storage operation each run in a child process; the harness kills the
operation after 10·T_test, so a client without timeouts fails instead of hanging (AC-5: I-1, I-2,
I-3, I-7). Connect timeout: full backlog-1 accept queue on Linux, 192.0.2.1:81 on macOS, with a
raw-connection probe that fails the test (never skips) when the environment cannot time out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
…CI in php:8.5-cli-trixie (CI-8 Task 2a fix F-1)

- FakeS3Harness::connectTimeoutEndpoint() fails (never skips) on libcurl < 8.11, whose connect-timeout
  wording Guzzle classifies as NetworkTimeoutException instead of ConnectTimeoutException.
- php.yml runs the job in the php:8.5-cli-trixie container (libcurl 8.14.1, + gd, git, unzip, Composer)
  instead of the runner's Ubuntu 24.04 (libcurl 8.5.0), and prints the PHP and libcurl versions.
- The 10·T_test guard starts at operation.php's "ready" line (child start-up has its own deadline);
  the harness also fails on a non-zero exit code.
- Timing upper bound A·T_test + 2 s + 1 s = 4 s; the A = 1 test asserts elapsed >= T_test (m3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
… single-attempt 404 NoSuchKey (CI-8 Task 2b)

- testServiceUnavailableThenSuccess: 503 ServiceUnavailable then 200; two requests, two SDK attempts.
  The PUT uploads 1 040 000 random bytes (Guzzle streams it, no Expect) and the retried request's body
  length and sha256 equal the file (I-4, E-28, M-2); the GET target holds only the 200 body (E-12).
- testNoSuchKeyIsSingleAttemptWithCode: 404 NoSuchKey, one attempt, code kept, not a connection error.
- FakeS3: scenarios unavailable_then_ok and no_such_key, requests() journal accessor, upload size and
  source sha256 in the operation result.
- README and CLAUDE.md: a failed download() may leave a partial target file; the caller deletes it,
  Handler::archive does not (R-B5, L-5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
…ound docblock, document both timing bounds (CI-8 Task 2a minors n1-n3)

- FakeS3Harness: a PHP start-up warning printed before "ready" no longer
  sends the guard back to the from-spawn deadline; "did not start" now
  prints stdout too.
- S3StorageFaultTest: delete the "D(A) = 6 s" docblock; the bound is 4 s.
- CLAUDE.md: the A = 2 tests use 4 s, the A = 1 test uses T_test + 1 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
… without a code (CI-8 Task 3a, R-B7/D-17)

register() appends one init step (NAME = chamber_orchestra_file.s3_redirect_guard)
to an S3Client's handler list. A fulfilled result with @metadata.statusCode
300-399 becomes exactly S3Exception: status in the message, no AWS error code,
connection_error false, the result kept for diagnostics. Other results and
rejections pass unchanged. Not wired into the extension yet (Task 3b).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
…omes an error (CI-8 Task 3b, R-B7)

With `http` set, the extension passes `allow_redirects: false` in the client's
`http` argument and sets `[S3RedirectGuard::class, 'register']` as the client
definition's configurator, so a 3xx ends the operation after one request:
301 -> PermanentRedirectException, any other 3xx -> S3Exception without an AWS
error code, never retried. Without `http` the client definition stays as in
8.1.4 (no allow_redirects, no configurator).

S3StorageRedirectTest (AC-17-AC-19) runs PUT and GET against a redirecting
fake server with a silent Location target. Recorded runs: v1 (no
allow_redirects, no guard) all 8 red; v2 (allow_redirects only) AC-17 green,
AC-18/AC-19 red (silent success). The extension tests check the http array,
the configurator, and on a compiled container exactly one guard step in
`init` with `retry` and `s3.permanent_redirect` in `sign`.

FakeS3Harness now holds the one 4 s bound (UPPER_BOUND), ATTEMPTS and the
test storage config, shared by the fault and redirect tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
…sk 4, R-B8, AC-3, AC-20)

With `http` set, the client's `http` argument also gets `curl => [CURLOPT_FORBID_REUSE => true]`, so
Guzzle never re-sends a streamed PUT on a dead reused connection and one SDK attempt is one HTTP request.
Without `http` the client definition stays exactly as in 8.1.4.

S3StorageKeepAliveTest (AC-20): fake server scenario keep_alive (warm-up GET 200 keep-alive; request 2
closed 0.8*T_test after its body, unanswered; then silence), warm-up download() before the guard, upload
of 1 040 000 B. Without R-B8: red 3/3, 4 requests on 3 connections, 3 PUTs for 2 SDK attempts. With
R-B8: green 3/3, 3 requests on 3 connections, PUTs = attempts = 2, upload() 1.43-1.87 s (bound 4 s).

Docs: README and CLAUDE.md state R-B8, the ext-curl requirement (container compile Error without it),
the rejected `stream` option (StreamHandler), that remove() rethrows unwrapped (false only for
NoSuchKey), and that a failed download may leave the S3 error XML in the target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
- Requirements / Dependencies: Symfony 8.1 and metadata-bundle 8.1, as in composer.json.
- http/retries: write literals; %env()% placeholders fail the > 0 / >= 1 check.
- A timeout of .inf or below 0.001 passes configuration, but Guzzle 8.2 rejects
  every request with InvalidArgumentException; it is not "no timeout".
- Stream-handler cases in the "do not bound" list fail instead when http is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
…R-B1, AC-1)

A timeout that is infinite or below 1 ms passed validation: Guzzle 7 then
silently disables the timeout (CURLOPT_TIMEOUT_MS = 0) and Guzzle 8 rejects
every request. Both keys now fail configuration processing with the key path.
The message is built with var_export, since thenInvalid's json_encode cannot
encode INF.

Docs: README and CLAUDE.md state the new rule; the stream-option rejection is
Guzzle 8+ only; composer suggest matches 8.1.* and lists ext-curl.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXB2dje72BXojVPbein4Rm
@wtorsi
wtorsi merged commit 1916019 into 8.1 Oct 20, 2026
1 check passed
@wtorsi wtorsi mentioned this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant