mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
* fix(s3): make GetObject atomic against concurrent same-key overwrites
A GetObject racing PutObject overwrites of the same key could return a
torn response assembled from two object versions: Content-Length, ETag,
and checksum headers from one version with body bytes from another.
When the newer body was longer than the advertised Content-Length, the
surplus bytes stayed on the wire and corrupted the keep-alive
connection's HTTP/1.1 framing (clients then log "Unsolicited response
received on idle HTTP channel", and the next request on that pooled
connection breaks). AWS S3 gives a concurrent read exactly one complete
version, never a mix.
Two gaps combined into the tear:
- S3Service.getObject read metadata and data as two unlocked reads,
while writers install them as two separate stores (objectStore, then
writeFile) under the bucket monitor. Take the same monitor around the
read pair so it can never straddle a write.
- S3Controller resolved response headers from a headObject snapshot but
streamed the body lazily at entity-write time via openObjectStream,
re-reading whatever data the key held by then. Serve both the full
and Range responses from the byte[] captured atomically with the
metadata, and fail loudly if a snapshot's data ever disagrees with
its declared size instead of corrupting the response framing.
The website index path now uses getObject so the served snapshot
carries its matching body as well.
Regression test: S3ConcurrentWriteReadTest#
concurrentOverwriteNeverPairsMetadataWithAnotherVersionsBody alternates
two fixed bodies of different lengths under concurrent readers and
asserts every read returns one complete version whose size and ETag
match its bytes. It fails on the previous code within seconds
("declared size=300 but body has 256 bytes") and passes with the fix.
Verified end-to-end with an AWS SDK Go v2 raced GET/PUT reproduction:
torn bodies, CRC checksum mismatches, and unsolicited-response warnings
on floci/floci:1.7.0; zero across 4 runs (~900k reads) on the patched
build. S3 suite: 1070/1070 green.
Change-Id: I4f4dbef49d85e0cdf13aaaca66dc8592db0fbed0
Signed-off-by: Thomas Kosiewski <tk@coder.com>
* fix(s3): serve conditional GETs and website requests from one snapshot
Review follow-ups on the torn-GET fix:
- Conditional GETs evaluated If-Match/If-None-Match/If-(Un)Modified-Since
against a separate headObject fetch and then served a later getObject
snapshot, so an overwrite landing between the two could return a
version the precondition never approved. Preconditions are now
evaluated against the same atomic snapshot that is served, making the
decision and the returned version consistent by construction.
- Website HEAD requests loaded the index document's bytes only to
discard them (headOnlyResponse strips the entity). The website
resolution carries metadata only again; the controller fetches the
atomic metadata+body snapshot just for GET renders, and HEAD builds
its headers without touching the data. Shared response-header
construction is extracted into objectResponseHeaders.
Change-Id: Ia116b6c6886febfde2bdabe3b4e2b4695617ab4f
Signed-off-by: Thomas Kosiewski <tk@coder.com>
---------
Signed-off-by: Thomas Kosiewski <tk@coder.com>