The presence service has a registry of active connections by user. After a recent change, complaints appeared: under load, operations sometimes fail, and data from the obtained snapshot unexpectedly affects the state of the registry itself. You need to review the diff and find the causes of the regression.
register(userId, connectionId) adds a connection for a user.unregister(userId, connectionId) removes a specific connection; if the user has no more connections, the user must not remain in the registry.snapshot() returns a snapshot of the current state:
userId;connectionId;PresenceRegistry.register/unregister for one user;snapshot().Example of a minimal check for the second scenario:
PresenceRegistry registry = new PresenceRegistry();
registry.register("u1", "c1");
var snapshot = registry.snapshot();
snapshot.get("u1").clear();
boolean stillPresent = registry.snapshot().get("u1").contains("c1");
After clearing the set from the snapshot, the internal state of the registry must not change.
snapshot() result.review — you need to find defects in the proposed PR changemain or unit test is sufficientPresenceRegistry instance is used concurrently by multiple threadsUse line comments to explain the problem, its impact, the fix and how to test it.