Fix critical bugs: overflow, thread safety, and correlation tracking#39
Conversation
…y, correlation ID preservation Co-authored-by: dexcompiler <115876036+dexcompiler@users.noreply.github.com>
|
@copilot Since |
Good question!
The
If we needed concurrent random generation without locks, The current implementation strikes the right balance: deterministic + thread-safe + performant. |
Addresses critical correctness and safety issues identified in code review of the distributed systems simulation.
VectorClock Deserialization Safety
Issue:
ReadFrom()castuintcount tointwithout bounds checking, enabling integer overflow on malicious inputs.Also added capacity check in
Increment()to fail-fast before exceeding MaxEntries (65,536 nodes).FailureInjector Thread Safety
System.Randomis not thread-safe. Wrapped all Random calls withLockto prevent state corruption:Distributed Tracing Fidelity
Retry logic was creating new
CorrelationIdper attempt, breaking trace chains. Added_correlationIdsdictionary to preserve original correlation across retries:Collection Iteration Safety
Poll()iterated_retrieswhileTryRetry()modified it. Snapshot collection before iteration to avoid TOCTOU:Documentation
DistributedAtLeastOnceCausalityShowcase.Run()with parameter descriptionsVectorClock.ReadFrom()Testing
Added boundary tests for VectorClock overflow conditions. All 182 tests pass (115 unit + 67 property).
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.