Repository navigation
Conversation
CheckIncoming compared the stored item's Cas field against the incoming Cas and returned early whenever the stored Cas was 0. Items are stored without a meaningful Cas, so the compare-and-swap never fired and a stale update could overwrite the value. Compare the incoming put's cas against the stored item's seq, as BEP 44 specifies, treating an absent cas (0) as no compare-and-swap requested.
|
Can you include a unit test that demonstrates it? Or even the black box test suite? |
There was a problem hiding this comment.
🟡 Changes recommended
The CAS behavior is critical for lost-update protection and should be covered by targeted unit tests to prevent regressions.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes BEP 44 compare-and-swap (CAS) enforcement for mutable puts by validating the incoming request’s cas against the stored item’s current sequence number (seq), ensuring stale updates are rejected as intended.
Changes:
- Replace the ineffective
stored.Cas-based early-accept logic with a BEP 44–aligned check:incoming.Cas != 0 && incoming.Cas != stored.Seq. - Clarify CAS semantics in
CheckIncomingvia updated inline documentation.
File summaries
| File | Description |
|---|---|
bep44/item.go |
Corrects CAS validation logic in CheckIncoming to compare incoming.Cas against stored.Seq per BEP 44. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // cas (compare-and-swap) is the sequence number the writer expects to be | ||
| // replacing; per BEP 44 it must equal the *stored* item's current seq, | ||
| // otherwise the put is rejected. An absent cas (0) means "no cas". | ||
| if incoming.Cas != 0 && incoming.Cas != stored.Seq { | ||
| return ErrCasHashMismatched |
Cover the cas acceptance and rejection matrix directly: an absent cas is ignored, a cas equal to the stored seq is accepted, and a cas that differs from the stored seq is rejected with ErrCasHashMismatched. The stored item's own Cas field is not consulted, and the sequence number check still runs ahead of the cas check. TestWrapperCas walks the same path through Wrapper.Put with signed mutable items, so a writer that still believes an older seq is current cannot overwrite the newer value.
There was a problem hiding this comment.
🟢 Approval recommended
The CAS validation bug is corrected in the right location and is backed by focused tests that exercise both direct validation and end-to-end Wrapper.Put behavior.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
Superseded by a9c967f, which compares cas against the stored sequence number in |
CheckIncomingcompared the stored item'sCasfield against the incomingitem's
Cas, and returned early (accept) wheneverstored.Caswas 0. Items arestored without a meaningful
Cas, sostored.Casis effectively always 0 andthe compare-and-swap check never fired — a stale update that should be rejected
was accepted, so the lost-update protection
casprovides did not hold.Per BEP 44 the incoming put's
casis the sequence number the writer expects tobe replacing, and must equal the stored item's current
Seq. This comparesincoming.Casagainststored.Seq, treating an absent cas (0) as "nocompare-and-swap requested".
Found with a black-box BEP 44 conformance suite; verified by rebuilding the DHT
server and re-running its
casandcas_type_confusionchecks, which now pass.