Fix concurrent map access for clients and inflights causes data race #99
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.
As per #98 and #96 - a data race was occurring when the primary server routine and client routines attempted to access the client inflight messages map at the same time, causing fatal errors.
The issue was reproduced placing the server under heavy load with inovex/mqtt-stresser, using qos=2 for both the publisher and subscriber (see #98).
This PR fixes the issue by returning reference maps of the original values, values in the case of inflight messages, pointers to clients in the case of the client map.
Profiling the solution before and after show a small but negligible reduction in mallocs. When running the above mentioned stress tests, data races or crashes are detected are no longer detected.
With many thanks to @muXxer for identifying the issue and providing a potential solution in #96 :)
Additionally, this PR increases the size of the inline publishing buffer in light of #95.
Finally, error message var naming in clients_test has been updated to better meet code standards.