Skip to content

feat(sandbox): add idempotent retry for sandbox creation and connection - #472

Merged
miclle merged 7 commits into
qiniu:masterfrom
DROWNING2003:master
Jul 29, 2026
Merged

feat(sandbox): add idempotent retry for sandbox creation and connection#472
miclle merged 7 commits into
qiniu:masterfrom
DROWNING2003:master

Conversation

@DROWNING2003

Copy link
Copy Markdown
Contributor
  • Auto-generate UUID idempotency key + Idempotency-Key header for Create
  • Add _retryCall method wrapping Create and Connect, retries on 408/5xx server errors and network errors
  • Configurable maxRetries via SandboxClient(max_retries=N) or SANDBOX_RETRY_MAX env var (default 5)
  • Sandbox.create(idempotency_key=...) optional parameter
  • Integration test for Git clone timeout retry
  • Example: examples/sandbox_idempotency_retry.py

- Add idempotency key auto-generation (uuid4) with Idempotency-Key header
- Add _retryCall method wrapping create/connect with configurable max_retries
- Retry on 408/5xx server errors and network errors (timeout, connection refused, etc.)
- Configurable via SandboxClient(max_retries=N) or SANDBOX_RETRY_MAX env var
- Add Sandbox.create(idempotency_key=...) optional parameter
- Add integration test for Git clone timeout retry scenario
- Add sandbox_idempotency_retry example
- Add SANDBOX_RETRY_MAX to .env.example
@qiniu-prow qiniu-prow Bot added the size/L label Jul 29, 2026

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review summary

Found two issues that prevent the advertised retry behavior from being reliably delivered and verified. Changed Python files compile successfully. The full pytest suite could not run in this workspace because requests and pytest are not installed.

View job run

Comment thread qiniu/services/sandbox/client.py
Comment thread tests/cases/test_services/test_sandbox/test_integration.py Outdated
…rrors

- Add exponential backoff with jitter (500ms → 10s) between retries
- Integration test: re-raise non-retryable 4xx errors instead of logging
- _is_retryable now checks SandboxError messages when status_code is 0
  (wrapped network errors like timeouts, connection refused)
- Extract _is_retryable_message for reuse
…integration test

- Add 'failed to resolve' DNS pattern to retryable message matching
- Integration test: raise on all 4xx/5xx except 408 instead of only 4xx
Comment thread qiniu/services/sandbox/client.py Outdated
Comment thread qiniu/services/sandbox/client.py Outdated
Comment thread tests/cases/test_services/test_sandbox/test_integration.py Outdated
…and add unit tests

_normalize_max_retries validates max_retries as non-negative integer.
_is_retryable inspects err.cause via ConnectionError/Timeout instead of
string matching. SandboxError carries cause from the underlying request
exception. Add 6 unit tests for retry/validation. Use GIT_REPO_URL.
Comment thread examples/sandbox_idempotency_retry.py Outdated
Comment thread tests/cases/test_services/test_sandbox/test_integration.py Outdated
…otency example

Sandbox.create now passes max_retries to SandboxClient internally.
Example verifies idempotency with dual creation and proper cleanup.
Remove test_create_retry_with_git_clone integration test.
@miclle
miclle merged commit 36135e1 into qiniu:master Jul 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants