Replace std::default_random_engine with std::mt19937 (rolling) #2843
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.
This PR addresses issue #2842, where std::default_random_engine can lead to periodic goal ID duplication due to its underlying implementation in GCC (minstd_rand0). When actions are executed frequently, this periodicity increases the likelihood of duplicate goal IDs, potentially causing unintended behavior.
In extreme cases, duplicate goal IDs can:
Trigger an exception when attempting to accept a new goal (goal ID already exists).
Extend the expiration time of the first goal when a duplicate ID is encountered.
To mitigate this, this PR replaces std::default_random_engine with std::mt19937, which provides a higher-quality random number generator with better distribution properties, reducing the risk of goal ID collisions.
Changes in this PR
std::default_random_engine → std::mt19937 in client_base.cpp
Ensures goal ID randomness to prevent collisions in high-frequency action executions.
Testing
In a 13-hour test, we observed periodic goal ID duplication when using std::default_random_engine.
Same goal ID appeared twice within a 10-minute period.
When goal ID retention was reduced to 1 minute, the issue no longer occurred.
With std::mt19937, goal ID duplication is effectively mitigated.
Impact
No ABI breakage.
Improves reliability of goal ID generation.
Addresses unintended goal expiration extension issues.