Send disconnection requests after non-API device unlinks

This commit is contained in:
Jonathan Klabunde Tomer
2025-05-06 13:36:41 -07:00
committed by GitHub
parent 7a91c4d5b7
commit cc7b030a41
16 changed files with 44 additions and 7 deletions

View File

@@ -580,6 +580,15 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
return Optional.of(aci);
}
/**
* Unlink a device from the given account. The device will be immediately disconnected if it is
* connected to any chat frontend, but it is the caller's responsibility to make sure that the
* account's *other* devices are disconnected, either by use of
* {@link org.whispersystems.textsecuregcm.auth.LinkedDeviceRefreshRequirementProvider} or
* directly by calling {@link DeviceDisconnectionManager#requestDisconnection}.
*
* @returns the updated Account
*/
public CompletableFuture<Account> removeDevice(final Account account, final byte deviceId) {
if (deviceId == Device.PRIMARY_ID) {
throw new IllegalArgumentException("Cannot remove primary device");

View File

@@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.auth.DisconnectionRequestManager;
import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration;
import org.whispersystems.textsecuregcm.entities.MessageProtos;
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
@@ -44,6 +45,7 @@ public class MessagePersister implements Managed {
private final AccountsManager accountsManager;
private final DynamicConfigurationManager<DynamicConfiguration> dynamicConfigurationManager;
private final ExperimentEnrollmentManager experimentEnrollmentManager;
private final DisconnectionRequestManager disconnectionRequestManager;
private final Duration persistDelay;
@@ -82,6 +84,7 @@ public class MessagePersister implements Managed {
final AccountsManager accountsManager,
final DynamicConfigurationManager<DynamicConfiguration> dynamicConfigurationManager,
final ExperimentEnrollmentManager experimentEnrollmentManager,
final DisconnectionRequestManager disconnectionRequestManager,
final Duration persistDelay,
final int dedicatedProcessWorkerThreadCount) {
@@ -90,6 +93,7 @@ public class MessagePersister implements Managed {
this.accountsManager = accountsManager;
this.dynamicConfigurationManager = dynamicConfigurationManager;
this.experimentEnrollmentManager = experimentEnrollmentManager;
this.disconnectionRequestManager = disconnectionRequestManager;
this.persistDelay = persistDelay;
this.workerThreads = new Thread[dedicatedProcessWorkerThreadCount];
@@ -257,9 +261,10 @@ public class MessagePersister implements Managed {
trimQueue(account, deviceId);
throw new MessagePersistenceException("Could not persist due to an overfull queue. Trimmed primary queue, a subsequent retry may succeed");
} else {
logger.warn("Failed to persist queue {}::{} due to overfull queue; will unlink device", account.getUuid(),
deviceId);
accountsManager.removeDevice(account, deviceId).join();
logger.warn("Failed to persist queue {}::{} due to overfull queue; will unlink device", accountUuid, deviceId);
accountsManager.removeDevice(account, deviceId)
.thenRun(() -> disconnectionRequestManager.requestDisconnection(accountUuid))
.join();
}
} finally {
messagesCache.unlockQueueForPersistence(accountUuid, deviceId);

View File

@@ -77,6 +77,7 @@ record CommandDependencies(
AccountsManager accountsManager,
ProfilesManager profilesManager,
ReportMessageManager reportMessageManager,
DisconnectionRequestManager disconnectionRequestManager,
MessagesCache messagesCache,
MessagesManager messagesManager,
KeysManager keysManager,
@@ -289,6 +290,7 @@ record CommandDependencies(
accountsManager,
profilesManager,
reportMessageManager,
disconnectionRequestManager,
messagesCache,
messagesManager,
keys,

View File

@@ -66,6 +66,7 @@ public class MessagePersisterServiceCommand extends ServerCommand<WhisperServerC
deps.accountsManager(),
deps.dynamicConfigurationManager(),
new ExperimentEnrollmentManager(deps.dynamicConfigurationManager()),
deps.disconnectionRequestManager(),
Duration.ofMinutes(configuration.getMessageCacheConfiguration().getPersistDelayMinutes()),
namespace.getInt(WORKER_COUNT));

View File

@@ -110,7 +110,10 @@ public class RemoveExpiredLinkedDevicesCommand extends AbstractSinglePassCrawlAc
final Mono<Long> accountUpdate = dryRun
? Mono.just((long) expiredDevices.size())
: deleteDevices(account, expiredDevices, maxRetries);
: deleteDevices(account, expiredDevices, maxRetries)
.flatMap(count ->
Mono.fromCompletionStage(getCommandDependencies().disconnectionRequestManager().requestDisconnection(account.getUuid()))
.then(Mono.just(count)));
return accountUpdate
.doOnNext(successCounter::increment)