The PR changed a small registry of active user sessions for online presence. After the change, the service sometimes returns an unexpected list of sessions and starts behaving unstably under concurrent load.
You need to review the changes and find the problems in the current after version.
userId, the registry must store a set of unique sessionId values.snapshot() must be safe while registrations and removals are happening in parallel.snapshot() must return an independent copy of the state that external code cannot use to corrupt the internal storage.PresenceRegistry.register("u1", ...) several times with different sessionId values, then obtain snapshot() and try to modify the nested set for the user.sessionsOf("u1") and compare the contents with the expected registry state.register() and unregister(), and in another thread call snapshot() in a loop.snapshot() result, and under concurrent operation there is a failure while traversing the data.Example launch scaffold:
var registry = new PresenceRegistry();
registry.register("u1", "s1");
registry.register("u1", "s2");
var snap = registry.snapshot();
snap.get("u1").clear();
System.out.println(registry.sessionsOf("u1"));
snapshot() must not affect PresenceRegistry.register(), unregister() and snapshot(), there must be no collection traversal errors.before/after changesjavac *.javajava DemoPresenceRegistry instance is used from multiple threadsUse line comments to explain the problem, its impact, the fix and how to test it.