Contargo / contargo-types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uniqueness check is not safe for concurrent modifications

olle opened this issue · comments

So the use of a local reference to the value held in any of the concurrent maps, for example a set of string values for the email addresses of some user UUID, is not guarded against concurrent modifications.

if (dataToCheck.containsKey(key)) {
Set<String> values = dataToCheck.get(key);
// only one presence and mapped to the requester's userUUID
if (!values.isEmpty()) { // there are values for this key
if (values.size() == 1 && values.contains(value)) { // only one value equals to the requested value: unique
return true;
} else { // more values or one not equal to the requested one: not unique
logger().info("detected non-unique value {}. claimed by {} but already taken by {}.", key, value,
String.join(",", values));
return false;
}
} else {
return true;
}

I believe the checks may fail between the if-statements, in case the set is changed in an unpredictible way. We've just recorded log-statements where the non-unique value is empty, hinting at it being cleared after the check of it being empty.

I'll try to address this in a fix.