mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 15:46:47 +00:00
Avoid concurrent modifications when notifying disconnection request listeners
This commit is contained in:
1 parent
6e79823f74
commit
1c4933e23c
1 file changed
+16
-8
+16
-8
@@ -209,14 +209,22 @@ public class DisconnectionRequestManager extends RedisPubSubAdapter<byte[], byte
|
||||
}
|
||||
|
||||
deviceIds.forEach(deviceId -> {
|
||||
listeners.getOrDefault(new AccountIdentifierAndDeviceId(accountIdentifier, deviceId), Collections.emptyList())
|
||||
.forEach(listener -> listenerEventExecutor.execute(() -> {
|
||||
try {
|
||||
listener.handleDisconnectionRequest();
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Listener failed to handle disconnection request", e);
|
||||
}
|
||||
}));
|
||||
final ArrayList<DisconnectionRequestListener> listenersForDevice = new ArrayList<>();
|
||||
|
||||
// This is a little weird, but it's a thread-safe way to get an immutable copy of the list of listeners for a
|
||||
// given device
|
||||
listeners.computeIfPresent(new AccountIdentifierAndDeviceId(accountIdentifier, deviceId), (_, existingListeners) -> {
|
||||
listenersForDevice.addAll(existingListeners);
|
||||
return existingListeners;
|
||||
});
|
||||
|
||||
listenersForDevice.forEach(listener -> listenerEventExecutor.execute(() -> {
|
||||
try {
|
||||
listener.handleDisconnectionRequest();
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Listener failed to handle disconnection request", e);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user