Skip to content

fix: retry on R2 ETag mismatch when client sends If-Match: * - #276

Merged
kptdobe merged 1 commit into
mainfrom
fix/ifmatch-wildcard-retry
May 12, 2026
Merged

kptdobe merged 1 commit into
mainfrom
fix/ifmatch-wildcard-retry

Conversation

@kptdobe

@kptdobe kptdobe commented May 11, 2026

Copy link
Copy Markdown
Contributor

Problem

When da-collab sends PUT with If-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 the PutObjectCommand, R2 returns 412.

The previous code treated any If-Match value as a non-retriable client conditional:

if (!effectiveConditionals?.ifMatch) {
  return putObjectWithVersion(...); // retry
}
return { status: 412 }; // no retry — even for If-Match: *

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 version

For 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

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

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kptdobe
kptdobe requested a review from bosschaert May 11, 2026 13:26
const shouldRetry = !effectiveConditionals?.ifMatch
|| effectiveConditionals.ifMatch === '*';
if (shouldRetry) {
return putObjectWithVersion(env, daCtx, update, body, guid, clientConditionals);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 ?

@kptdobe
kptdobe merged commit 3634d98 into main May 12, 2026
8 of 9 checks passed
@kptdobe
kptdobe deleted the fix/ifmatch-wildcard-retry branch May 12, 2026 06:45
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))
@adobe-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.8.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

4 participants