moquette-io / moquette

Java MQTT lightweight broker
http://moquette-io.github.io/moquette/
Apache License 2.0
2.27k stars 814 forks source link

Fixes 841: Incorrect reference used in compareAndSet in CTrie.cleanTomb. #842

Open hylkevds opened 2 weeks ago

hylkevds commented 2 weeks ago

cleanTomb used compareAndSet to update a reference, but incorrectly re-fetched the 'original' instead of using the version that was used to make the copy. The result was that in case of a conflict, the changes of one thread would be overwritten by another thread.

If cleanTomb failes when called from the remove method, the node is already replaced by a TNode, and the subsequent call will re-try to clean the TNode. The node removed by cleanTomb may already have been replaced with a live node by another thread, so cleanTomb checks if the removed node actually was the intended node before committing the results.