Don't close connections on keepalive if the client is enrolled in the "read live messages from FoundationDB" experiment

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2026-10-15 10:36:10 -04:00
1 parent d1073e00bd
commit 92dc1fe597
3 files changed
+11 -6

No files matched your search

@@ -1290,7 +1290,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
webSocketEnvironment.jersey().register(new RequestStatisticsFilter(TrafficSource.WEBSOCKET));
webSocketEnvironment.jersey().register(MultiRecipientMessageProvider.class);
webSocketEnvironment.jersey().register(new MetricsApplicationEventListener(TrafficSource.WEBSOCKET, clientReleaseManager));
webSocketEnvironment.jersey().register(new KeepAliveController(redisMessageAvailabilityManager));
webSocketEnvironment.jersey().register(new KeepAliveController(redisMessageAvailabilityManager, experimentEnrollmentManager));
webSocketEnvironment.jersey().register(new TimestampResponseFilter());
final PersistentTimer persistentTimer = new PersistentTimer(rateLimitersCluster, clock);
@@ -1352,7 +1352,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
webSocketEnvironment.getRequestLog(), Duration.ofMillis(60000));
provisioningEnvironment.setConnectListener(new ProvisioningConnectListener(provisioningManager, asnInfoProviderSupplier, clientReleaseManager, provisioningWebsocketTimeoutExecutor, Duration.ofSeconds(90)));
provisioningEnvironment.jersey().register(new MetricsApplicationEventListener(TrafficSource.WEBSOCKET, clientReleaseManager));
provisioningEnvironment.jersey().register(new KeepAliveController(redisMessageAvailabilityManager));
provisioningEnvironment.jersey().register(new KeepAliveController(redisMessageAvailabilityManager, experimentEnrollmentManager));
provisioningEnvironment.jersey().register(new TimestampResponseFilter());
registerExceptionMappers(environment, webSocketEnvironment, provisioningEnvironment);
@@ -21,8 +21,10 @@ import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.auth.AuthenticatedDevice;
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil;
import org.whispersystems.textsecuregcm.push.RedisMessageAvailabilityManager;
import org.whispersystems.textsecuregcm.storage.MessagesManager;
import org.whispersystems.websocket.session.WebSocketSession;
import org.whispersystems.websocket.session.WebSocketSessionContext;
@@ -34,13 +36,16 @@ public class KeepAliveController {
private final Logger logger = LoggerFactory.getLogger(KeepAliveController.class);
private final RedisMessageAvailabilityManager redisMessageAvailabilityManager;
private final ExperimentEnrollmentManager experimentEnrollmentManager;
private static final String CLOSED_CONNECTION_AGE_DISTRIBUTION_NAME = name(KeepAliveController.class,
"closedConnectionAge");
public KeepAliveController(final RedisMessageAvailabilityManager redisMessageAvailabilityManager) {
public KeepAliveController(final RedisMessageAvailabilityManager redisMessageAvailabilityManager,
final ExperimentEnrollmentManager experimentEnrollmentManager) {
this.redisMessageAvailabilityManager = redisMessageAvailabilityManager;
this.experimentEnrollmentManager = experimentEnrollmentManager;
}
@GET
@@ -48,7 +53,8 @@ public class KeepAliveController {
@WebSocketSession WebSocketSessionContext context) {
maybeAuth.ifPresent(auth -> {
if (!redisMessageAvailabilityManager.isLocallyPresent(auth.accountIdentifier(), auth.deviceId())) {
if (!(experimentEnrollmentManager.isEnrolled(auth.accountIdentifier(), MessagesManager.READ_LIVE_MESSAGES_FROM_FOUNDATIONDB_EXPERIMENT_NAME) ||
redisMessageAvailabilityManager.isLocallyPresent(auth.accountIdentifier(), auth.deviceId()))) {
final Duration age = Duration.between(context.getClient().getCreated(), Instant.now());
@@ -74,8 +74,7 @@ public class MessagesManager {
@VisibleForTesting
static final String MIRROR_READS_EXPERIMENT_NAME = "foundationDbMirrorReads";
@VisibleForTesting
static final String READ_LIVE_MESSAGES_FROM_FOUNDATIONDB_EXPERIMENT_NAME = "foundationDbReadLiveMessages";
public static final String READ_LIVE_MESSAGES_FROM_FOUNDATIONDB_EXPERIMENT_NAME = "foundationDbReadLiveMessages";
private final MessagesDynamoDb messagesDynamoDb;
private final MessagesCache messagesCache;