mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
63ea717a7511df0db8f7eb3bdaac4ee74fb3b842
Addresses five architect findings across two review rounds, all on
the authority package introduced in 5c663b8. The core S2 boundary
(Publisher is the sole minter, identity keyed by (VolumeID,
ReplicaID), Directive is the only policy seam) stays unchanged;
this commit tightens correctness of delivery and the strength of
the non-forgeability proof.
1. Close-safe delivery (High). apply()'s fan-out ran outside
pub.mu and could race with cancel()/Run-exit closing the same
channel. The former deliverLatest free function was not
close-aware — a concurrent close would produce send-on-closed
panics, and its drain-retry loop on a closed channel (where
receive is permanently ready with zero value) would spin
forever.
Fix: subscription now owns a sync.Mutex + closed flag. New
methods subscription.deliver() and subscription.close() both
acquire s.mu; deliver() returns early if closed, and close()
is idempotent. The deliverLatest free function is gone;
apply() calls s.deliver(next). cancelSubscription and
closeAllSubscriptions call target.close() instead of closing
target.ch directly.
Regression: TestPublisher_CancelDuringDeliveryDoesNotPanic
stress-runs 50 concurrent subscribe/cancel goroutines against
200 concurrent Refresh asks on the same (vid, rid). Asserts no
panic and no hang within 5 s.
2. Catch-up ordering race (High). Subscribe() registered the new
subscriber in p.subs under pub.mu, then released the lock and
did a blocking sub.ch <- st.info. A concurrent apply() could
deliver a newer fact first; the delayed catch-up would then
enqueue the older fact, producing stale/out-of-order delivery
on a route that must converge to current authority truth.
Fix: the catch-up send now happens INSIDE the pub.mu critical
section, immediately after the subs-map insert. Because sub.ch
is cap=1 and the fresh subscription is invisible to any other
goroutine until pub.mu is released, the catch-up send is
guaranteed non-blocking. Any later apply() either runs before
us (catch-up state IS current) or sees us in the subs map and
drains our stale catch-up via deliver(). Strict ordering.
Regression:
TestPublisher_LateSubscriberReceivesLatestUnderConcurrentPublish
runs 200 iterations of (concurrent Reassign + fresh Subscribe +
drain); asserts drained epoch <= current authoritative epoch
every iteration.
3. AST non-forgeability proof gap — deferred-mutation bypass
(Medium). The earlier AST walker explicitly skipped short
declarations (x := adapter.AssignmentInfo{}), so the pattern
x := adapter.AssignmentInfo{}
x.Epoch = userInput
bypassed both checks: the literal is zero-valued so check (a)
did not trigger, and the short-decl path was ignored in (b).
Fix: auditNonForgeability now handles the AssignStmt branch
with Tok == token.DEFINE; any RHS that is a composite literal
of AssignmentInfo type is flagged as the deferred-mutation
bypass shape, regardless of field values. Also added the
long-decl-with-value case: var x = adapter.AssignmentInfo{}.
Regression (two synthetic-source tests that exercise the audit
function directly):
- TestNonForgeability_CatchesShortDeclBypass
- TestNonForgeability_CatchesVarDeclBypass
4. AST non-forgeability proof gap — pointer form (Medium,
subsequent round). After the short-decl fix, the architect
noted the same bypass in pointer form was still outside the
proof:
x := &adapter.AssignmentInfo{}
x.Epoch = userInput
The AST walker only recognized a bare *ast.CompositeLit on the
RHS, missing the UnaryExpr(&, CompositeLit) wrapper.
Fix: new helper unwrapAddrOfCompositeLit recognizes both
X{...} and &X{...}. Both GenDecl-with-value and AssignStmt
branches use it.
Regression:
- TestNonForgeability_CatchesPointerShortDeclBypass
- TestNonForgeability_CatchesPointerVarDeclBypass
5. Doc drift (Low). Two doc blocks still described the pre-fix²
state: docs/p14-s2-design.md said "simple 'forbidden
constructor' grep" and docs/p14-s2-closure.md listed
Unsubscribe as a Publisher method. Both updated to reflect the
AST-based whole-repo walker (covering value and pointer
forms) and the per-subscription cancel API with no key-wide
unsubscribe verb. Test count in closure.md bumped to 26 and
pointer-form test names added to the verification list.
No changes to engine, adapter, transport, ops, storage, or
sparrow. Authority tests: 26 pass. Full module: 12 packages pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Languages
Go
84.5%
Rust
7.9%
Shell
2.7%
templ
1.6%
Java
1%
Other
2%