Repository navigation
Description
Summary
putObject does not honour If-None-Match or If-Match, so conditional writes always succeed and
412 PreconditionFailed is unreachable.
Verified against 103c843 (v0.76.0):
$ grep -rn "If-None-Match\|If-Match\|PreconditionFailed" --include="*.go" . | grep -v _test
(no matches)
Why this matters to me
Two reasons, in objectfs.
1. Not clobbering an intact object. objectfs's Create currently issues an unconditional
PutObject(key, []byte{}), and its Lookup collapses every HeadObject error to ENOENT — so a
throttle or a permission error reads as "file absent" and the next Create zeroes a file that was
perfectly fine. The fix is If-None-Match: *, which turns the race into a 412 instead of silent
destruction. I can't write a regression test for that without the emulator returning the 412.
2. Evaluating S3 conditional writes as a replacement for a Raft implementation. objectfs has a
partially-built consensus layer for multi-node coordination. Since AWS added conditional writes to
S3 (Aug 2024), compare-and-swap on an object is available directly, which for this use case is
strictly simpler than running Raft. Substrate is where I'd want to develop and test that before
committing to the design, because the failure modes (lost update under concurrent CAS, retry
storms) are precisely what an emulator is good at reproducing deterministically and real S3 is not.
What I need
| Request | Precondition | Response |
|---|---|---|
PUT with If-None-Match: * |
key absent | 200, write proceeds |
PUT with If-None-Match: * |
key present | 412 PreconditionFailed, no write |
PUT with If-Match: "<etag>" |
current ETag matches | 200, write proceeds |
PUT with If-Match: "<etag>" |
current ETag differs | 412 PreconditionFailed, no write |
PUT with If-Match: "<etag>" |
key absent | 404 NoSuchKey |
GET/HEAD with If-None-Match: "<etag>" |
matches | 304 Not Modified |
GET/HEAD with If-Match: "<etag>" |
differs | 412 PreconditionFailed |
Notes on real-S3 behaviour worth matching:
- The
412body is the standard XML error with<Code>PreconditionFailed</Code>; the Go SDK
surfaces it as a modelled error the caller matches on, so the code string matters. - The write must not happen on a
412. The interesting bug class here is a partial apply, so a
test asserting the object body is unchanged after a rejected conditional PUT is the one I care
about most. If-None-Match: *is the only form S3 supports for that header on PUT (no ETag list).- Under concurrency, exactly one of N simultaneous
If-None-Match: *PUTs to the same key must
succeed. If substrate's state layer can guarantee that atomically, it is directly usable as a CAS
primitive; if it can't, that's worth knowing explicitly, and I'd rather find out in the emulator.
DeleteObject also accepts If-Match in real S3, but I don't need it — mentioning only so the scope
is a deliberate choice rather than an oversight.
Acceptance
Table test over the seven rows, plus one concurrency test asserting exactly-one-winner across N
parallel If-None-Match: * PUTs, plus an assertion that a 412'd PUT leaves the stored body byte-
identical.
Activity
scttfrdmn commentedon Jul 31, 2026
Answering your explicit request to be told if substrate cannot guarantee the
concurrency property rather than have it papered over — because as things stand,
it cannot, and the honest answer changes what the fix should look like.
StateManager(emulator/types.go:96-110) exposes onlyGet/Put/Delete/List:no compare-and-swap, no conditional put, no version token.
MemoryStateManager(
emulator/state.go:51) is the only implementation and is last-write-wins. So anaive
If-None-Match: *implementation that reads-then-writes has a windowbetween the existence check and the
Put, and N concurrent PUTs of the same newkey would all return 200 — the exact opposite of the exactly-one-winner
property you are testing for.
Exactly-one-winner needs a striped per-key mutex on
S3Pluginheld acrosscheck→Put. That is cheap and I intend to do it, but it is worth being precise
about what it buys: a process-local guarantee. It is airtight for substrate's
single-process topology, which is how every test uses it, and it would not hold
for two processes sharing a store. I would rather document that boundary than
have you discover it later. If you are running one emulator process — and the
If-None-Matchdistributed-lock pattern you are testing is a single-writer testanyway — the guarantee holds where you need it.
Scheduled on v0.79.0, after #396 (now up as #405). The read preconditions
(
If-Match/If-None-Matchon GET → 412/304) have to sit before the range stepin
getObject, which is why I sequenced it second rather than first; #405 putsthat shared response path in one place, so this lands as a small change rather
than a third copy of the header logic.
chore(release): v0.80.0 (#423)