ivukotic/plugins

Race condition in Collector#connectedEvent

Closed this issue · 3 comments

The Collector contains this code:

if (cmap.size() > maxConnections.get())
    maxConnections.set(cmap.size());

This code is called by several threads concurrently. Since both the size of the map and the value of maxConnections may change between the test and the update, this code is subject to a race condition.

while true - there is a possibility for a stale value to be used, it really does not matter - one of the next connections will fix the value. This value is just used for monitoring. Still I'll fix it as soon as I learn how :)

It is not just a matter of a stale value. You may have decreasing max. E.g. while checking the connection you have camp.size() 100 and maxConnections.get() 99, but then immediately 99 connections terminate, settings maxConnection to 1.

fixed. now cmap is private, and method made synchronized.