Repository navigation
Conversation
The nodetests target no longer compiled, so none of the csnode unit tests could run. Test-only change: production code is untouched. - conveyer_tests: PoolMetaInfo gained a `reward` field after `timestamp`, so the aggregate initializer was shifted by one. Pass an empty reward; applyCharacteristic adds the reward user field only when it is non-empty, so expectations are unchanged. - poolsynchronizer_tests: PoolSynchronizer::neighbours() was removed in 3ed6b98 (new synchronization algorithm). Neighbours are now a private unordered_map, so the "sorted by sequence" invariant no longer exists. Drop the helper and its assertion from the already DISABLED test, with a comment explaining why. Result with ENABLE_TESTS=ON (GCC 13, Boost 1.83 static): nodetests 110/110, lmdbxxtests 13/13 and lib_system 49/49 pass. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This made the `system` suite hang on the GitHub runner (ctest timeout at 300 s
in run 37647459022). Test-only change: production code is untouched.
- The writer generated a value "different from previous" with
`do { ... } while (randomValue != previous.data())`. The condition is
inverted: on the first pass previous is 0 and values are drawn from
[1, INT_MAX], so the loop never ends. Locally the writer thread usually
started after `isRunning` was already false, which hid the bug; on the runner
it started first and spun forever. Use `==`.
- With the loop fixed, a second race became visible: the reader's
wait_for(250 ms) can time out before the writer stored anything, and then
`desired != previous` compares 0 with 0. Only assert once a value has been
written.
Locally: 3000/3000 repetitions pass, and 1000/1000 with every core busy.
Before the fix it hung within 4 repetitions.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
cs::LockFreeChanger replaces its value with std::atomic_compare_exchange on a std::shared_ptr, but read the same shared_ptr with plain, non-atomic accesses: - exchange() itself: `current = data_;` - operator-> and operator* (and so data()). A reader copying the shared_ptr while a writer swaps it is a data race on the control block, which can free the value under the reader (use-after-free). Production user: ConfigHolder (csnode/configholder.hpp), which serves ConfigHolder::instance().config() to the whole node while config::Observer::configChanged can exchange it on a config reload. Fix, keeping interface and behaviour unchanged: - use std::atomic_load_explicit (same free-function family the class already uses for compare_exchange) for every read of data_; - operator* keeps the loaded shared_ptr alive while copying the value; - add the missing #include <memory>. Evidence: - ThreadSanitizer, minimal program with 2 writers and 2 readers for 300 ms: 8 data-race reports before, 0 after (3 runs). - tests: LockFreeChanger.BaseUsage crashed (SIGSEGV/abort) in 9 of 30 runs locally before the fix. Not changed (pre-existing, needs an API change): ConfigHolder::config() returns a raw `const Config*`. After a reload, the previous Config can be freed while a caller still holds that pointer. Cost: with libstdc++, atomic_load on a shared_ptr takes an uncontended lock from a small lock pool. config() is called per round/event, not in tight loops. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The hang is in the test, not in cs::Process. Diagnosis on the GitHub runner under stress-ng (run 37689274802) hung at iteration 1. The log showed "Launch count 250 / Finish count 250", so every `finished` signal was delivered. gdb showed a single thread left, spinning in Process_HighLoadUsage_Test::TestBody(). Two busy-waits could miss their event: - After the last launch the test set `lastExecution = true` and spun until `finished` reset it to false. Under load the last child (it runs ~10 ms) can finish and emit `finished` before the flag is set to true, and then nothing ever clears it. Wait on finishCount instead, with a 10 s deadline, so a really lost signal fails the assertions instead of hanging. - `while (!process.isRunning());` right after the first launch spins forever if the child is already gone. Also stop when it has already finished. Test-only change: production code (lib/system/process.hpp) is untouched. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Nov 4, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this PR
With
ENABLE_TESTS=ONthenodeteststarget no longer compiles on a current toolchain (GCC 13), and two tests of thesystemsuite can hang. One of the hangs exposed a real defect:cs::LockFreeChangerreplaces its value withstd::atomic_compare_exchangeon astd::shared_ptr, but reads the sameshared_ptrwithout atomic access. A reader copying it while a writer swaps it is a data race on the control block and can free the value under the reader. The production user isConfigHolder, read by the whole node while a config reload can replace it.What changes
lib/include/lib/system/lockfreechanger.hpp: every read ofdata_usesstd::atomic_load_explicit(the same free-function family the class already uses for the compare-exchange);operator*keeps the loadedshared_ptralive while copying the value;#include <memory>added. Interface and behaviour unchanged.tests/csnode/conveyer_tests.cpp:PoolMetaInfogained arewardfield aftertimestamp; the aggregate initializer is shifted accordingly (empty reward, expectations unchanged).tests/csnode/poolsynchronizer_tests.cpp:PoolSynchronizer::neighbours()was removed in 3ed6b98; the helper and its assertion are dropped from the already disabled test.tests/lib_system/lib_system_tests.cpp(LockFreeChanger.BaseUsageSimple): the writer's "different from previous" loop had an inverted condition and never ended when the writer thread started first; the reader asserts only once a value was written.tests/lib_system/process_tests.cpp(Process.HighLoadUsage): two busy-waits could miss their event under load (a lost wake-up in the test); the test now waits on the finish count with a deadline.lib/system/process.hppis untouched.Effect on the network
None. Only the test suite and the atomicity of
LockFreeChangerreads change; nothing on the wire or in consensus.Tests
Built and run on 4a95aaa with GCC 13 and Boost 1.83 (static):
nodetests,lmdbxxtestsandlib_systemall pass. Before the fix,LockFreeChanger.BaseUsagecrashed in 9 of 30 local runs, and ThreadSanitizer reported 8 data races on a small program with 2 writers and 2 readers (0 after). The build also needs-include cstdint -include cstddefon GCC 13 for two third-party/legacy headers; that is a build-flag matter and is not part of this PR.Same change in the community fork: CreditsCommunity#1, #2 and #3, running on mainnet community nodes.