fix: retry on R2 ETag mismatch when client sends If-Match: * - #276
Merged
Merged
Conversation
If-Match: * asserts document existence only (already verified before the R2 write). When a concurrent write changes the ETag between the existence check and the PutObjectCommand, R2 returns 412. The previous code treated any If-Match value as a non-retriable client conditional, so this spurious 412 propagated to the caller (da-collab) instead of being retried silently. Fix: treat If-Match: * the same as the no-conditional path on R2 ETag mismatch — re-fetch the current state and retry. Only a specific ETag (If-Match: "<hash>") means the caller requires a precise version and warrants a non-retriable 412. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| const shouldRetry = !effectiveConditionals?.ifMatch | ||
| || effectiveConditionals.ifMatch === '*'; | ||
| if (shouldRetry) { | ||
| return putObjectWithVersion(env, daCtx, update, body, guid, clientConditionals); |
Contributor
There was a problem hiding this comment.
Old code mentions "retry limit" though I don't see code for that. Seems like there should be a limit otherwise it might be possible to stack overflow?
Contributor
Author
There was a problem hiding this comment.
I agree. I do not really understand the original code.
I do not think the "under retry limit" was there before. No behavior change but it is worth understanding why.
@karlpauls could you please review and comment ?
bosschaert
approved these changes
May 11, 2026
adobe-bot
pushed a commit
that referenced
this pull request
May 12, 2026
## [1.8.1](v1.8.0...v1.8.1) (2026-05-12) ### Bug Fixes * retry on R2 ETag mismatch when client sends If-Match: * ([#276](#276)) ([3634d98](3634d98))
Collaborator
|
🎉 This PR is included in version 1.8.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When da-collab sends
PUTwithIf-Match: *, da-admin correctly checks document existence first. It then uses the document's current ETag for the actual R2 write (If-Match: <etag>). If a concurrent write (e.g. during a Durable Object live migration) changes the ETag between the existence check and thePutObjectCommand, R2 returns 412.The previous code treated any
If-Matchvalue as a non-retriable client conditional:This conflates two distinct semantics:
If-Match: *— wildcard, asserts existence only (already verified before the write)If-Match: "<etag>"— specific version lock, caller requires that exact versionFor the wildcard case, the document still exists after the ETag mismatch — the retry behaviour should be identical to the no-conditional (internal) path.
Fix
Retry on R2 ETag mismatch when the client sent
If-Match: *, exactly as internal writes do. Only a specific ETag value keeps the non-retriable 412.Tests
putObjectWithVersion retries on ETag mismatch when If-Match: * is sent— verifies the retry succeeds (was failing before this fix)putObjectWithVersion returns 412 without retry when client sends specific ETag— verifies specific-ETag behaviour is unchanged🤖 Generated with Claude Code