mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 00:56:50 +00:00
Avoid logging CallNotPermittedExceptions
This commit is contained in:
1 parent
5f24e3f771
commit
94e412031a
23 files changed
+291
-58
No files matched your search
@@ -207,6 +207,7 @@ import org.whispersystems.textsecuregcm.limits.RateLimitByIpFilter;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimitChallengeManager;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import org.whispersystems.textsecuregcm.mappers.BackupExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.CallNotPermittedExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.CompletionExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.DeviceLimitExceededExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.IOExceptionMapper;
|
||||
@@ -1405,6 +1406,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||
List.of(
|
||||
new LoggingUnhandledExceptionMapper(),
|
||||
new CompletionExceptionMapper(),
|
||||
new CallNotPermittedExceptionMapper(),
|
||||
new IOExceptionMapper(),
|
||||
new RateLimitExceededExceptionMapper(),
|
||||
new InvalidWebsocketAddressExceptionMapper(),
|
||||
|
||||
+10
-6
@@ -6,6 +6,7 @@
|
||||
package org.whispersystems.textsecuregcm.auth;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
|
||||
import io.netty.resolver.dns.DnsNameResolver;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
@@ -14,10 +15,8 @@ import java.net.URI;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -27,7 +26,6 @@ import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfigurati
|
||||
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
|
||||
import org.whispersystems.textsecuregcm.http.FaultTolerantHttpClient;
|
||||
import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
|
||||
public class CloudflareTurnCredentialsManager {
|
||||
@@ -133,10 +131,16 @@ public class CloudflareTurnCredentialsManager {
|
||||
|
||||
final HttpResponse<String> response;
|
||||
try {
|
||||
response = cloudflareTurnClient.sendAsync(getCredentialsRequest, HttpResponse.BodyHandlers.ofString()).join();
|
||||
} catch (CompletionException e) {
|
||||
response = cloudflareTurnClient.send(getCredentialsRequest, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (Exception e) {
|
||||
|
||||
if (e instanceof CallNotPermittedException cnpe) {
|
||||
// the circuit breaker is open, and this can escape up to the exception mapper
|
||||
throw cnpe;
|
||||
}
|
||||
|
||||
logger.warn("failed to make http request to Cloudflare Turn: {}", e.getMessage());
|
||||
throw new IOException(ExceptionUtils.unwrap(e));
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
if (response.statusCode() != Response.Status.CREATED.getStatusCode()) {
|
||||
|
||||
-9
@@ -27,7 +27,6 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.identity.IdentityType;
|
||||
import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
|
||||
import org.whispersystems.textsecuregcm.redis.FaultTolerantPubSubConnection;
|
||||
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisClient;
|
||||
@@ -120,10 +119,6 @@ public class DisconnectionRequestManager extends RedisPubSubAdapter<byte[], byte
|
||||
|
||||
/**
|
||||
* Adds a listener for disconnection requests for a specific authenticated device.
|
||||
*
|
||||
* @param accountIdentifier TODO
|
||||
* @param deviceId TODO
|
||||
* @param listener the listener to register
|
||||
*/
|
||||
public void addListener(final UUID accountIdentifier, final byte deviceId, final DisconnectionRequestListener listener) {
|
||||
listeners.compute(new AccountIdentifierAndDeviceId(accountIdentifier, deviceId), (_, existingListeners) -> {
|
||||
@@ -138,10 +133,6 @@ public class DisconnectionRequestManager extends RedisPubSubAdapter<byte[], byte
|
||||
|
||||
/**
|
||||
* Removes a listener for disconnection requests for a specific authenticated device.
|
||||
*
|
||||
* @param accountIdentifier TODO
|
||||
* @param deviceId TODO
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
public void removeListener(final UUID accountIdentifier, final byte deviceId, final DisconnectionRequestListener listener) {
|
||||
listeners.computeIfPresent(new AccountIdentifierAndDeviceId(accountIdentifier, deviceId), (_, existingListeners) -> {
|
||||
|
||||
+2
@@ -18,6 +18,7 @@ import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.glassfish.jersey.server.ManagedAsync;
|
||||
import org.whispersystems.textsecuregcm.auth.AuthenticatedDevice;
|
||||
import org.whispersystems.textsecuregcm.auth.CloudflareTurnCredentialsManager;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
@@ -54,6 +55,7 @@ public class CallRoutingControllerV2 {
|
||||
@ApiResponse(responseCode = "401", description = "Account authentication check failed.")
|
||||
@ApiResponse(responseCode = "422", description = "Invalid request format.")
|
||||
@ApiResponse(responseCode = "429", description = "Rate limited.")
|
||||
@ManagedAsync
|
||||
public GetCallingRelaysResponse getCallingRelays(final @Auth AuthenticatedDevice auth)
|
||||
throws RateLimitExceededException, IOException {
|
||||
|
||||
|
||||
+10
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.grpc;
|
||||
|
||||
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
|
||||
import io.grpc.ForwardingServerCall;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.ServerCall;
|
||||
@@ -12,6 +13,7 @@ import io.grpc.ServerCallHandler;
|
||||
import io.grpc.ServerInterceptor;
|
||||
import io.grpc.Status;
|
||||
import io.grpc.StatusRuntimeException;
|
||||
import io.lettuce.core.RedisException;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import org.slf4j.Logger;
|
||||
@@ -66,6 +68,13 @@ public class ErrorMappingInterceptor implements ServerInterceptor {
|
||||
ImpossibleEvents.logImpossible(log, e.getMessage(), e);
|
||||
yield GrpcExceptions.unavailable();
|
||||
}
|
||||
case CallNotPermittedException _ -> GrpcExceptions.unavailable();
|
||||
case RedisException e -> {
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
log.warn("RPC {} encountered RedisException", call.getMethodDescriptor().getFullMethodName(), e);
|
||||
}
|
||||
yield GrpcExceptions.unavailable();
|
||||
}
|
||||
case null -> {
|
||||
log.error("RPC {} finished with status UNKNOWN: {}",
|
||||
call.getMethodDescriptor().getFullMethodName(), status.getDescription());
|
||||
@@ -73,7 +82,7 @@ public class ErrorMappingInterceptor implements ServerInterceptor {
|
||||
}
|
||||
default -> {
|
||||
log.error("RPC {} finished with status UNKNOWN",
|
||||
call.getMethodDescriptor().getFullMethodName(), status.getCause());
|
||||
call.getMethodDescriptor().getFullMethodName(), cause);
|
||||
yield GrpcExceptions.unavailable();
|
||||
}
|
||||
};
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2026 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.mappers;
|
||||
|
||||
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||
|
||||
public class CallNotPermittedExceptionMapper implements ExceptionMapper<CallNotPermittedException> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(final CallNotPermittedException exception) {
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE).build();
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -35,9 +35,10 @@ import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisClusterClient;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.util.ResilienceUtil;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.Pair;
|
||||
import org.whispersystems.textsecuregcm.util.RedisClusterUtil;
|
||||
import org.whispersystems.textsecuregcm.util.ResilienceUtil;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -99,7 +100,10 @@ public class PushNotificationScheduler implements Managed {
|
||||
Util.sleep(1000);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Exception while processing scheduled notifications", e);
|
||||
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Exception while processing scheduled notifications", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(EXCEPTION_PAUSE);
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
public class ClusterLuaScript {
|
||||
@@ -109,7 +110,9 @@ public class ClusterLuaScript {
|
||||
return connection.sync().eval(script, scriptOutputType, keys, args);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log.warn("Failed to execute script", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
log.warn("Failed to execute script", e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -123,7 +126,9 @@ public class ClusterLuaScript {
|
||||
return connection.async().eval(script, scriptOutputType, keys, args);
|
||||
}
|
||||
|
||||
log.warn("Failed to execute script", throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
log.warn("Failed to execute script", throwable);
|
||||
}
|
||||
throw new RedisException(throwable);
|
||||
}).toCompletableFuture();
|
||||
}
|
||||
@@ -133,6 +138,10 @@ public class ClusterLuaScript {
|
||||
|
||||
return connection.reactive().evalsha(sha, scriptOutputType, keys, args)
|
||||
.onErrorResume(RedisNoScriptException.class, _ -> connection.reactive().eval(script, scriptOutputType, keys, args))
|
||||
.doOnError(throwable -> log.warn("Failed to execute script", throwable));
|
||||
.doOnError(throwable -> {
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
log.warn("Failed to execute script", throwable);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+24
-8
@@ -818,7 +818,9 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
connection.async().set(key, deviceInfoJson, SetArgs.Builder.ex(RECENTLY_ADDED_DEVICE_TTL))))
|
||||
.whenComplete((_, pubSubThrowable) -> {
|
||||
if (pubSubThrowable != null) {
|
||||
logger.warn("Failed to record recently-created device", pubSubThrowable);
|
||||
if (!ExceptionUtils.isBreakerOpen(pubSubThrowable)) {
|
||||
logger.warn("Failed to record recently-created device", pubSubThrowable);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1565,7 +1567,9 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
DELETION_REASON_TAG_NAME, deletionReason.tagValue)
|
||||
.increment();
|
||||
} catch (final RuntimeException e) {
|
||||
logger.warn("Failed to delete account", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to delete account", e);
|
||||
}
|
||||
throw e;
|
||||
} finally {
|
||||
sample.stop(deleteTimer);
|
||||
@@ -1658,7 +1662,9 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
try {
|
||||
account.ifPresent(this::redisSet);
|
||||
} catch (RedisException e) {
|
||||
logger.warn("Failed to cache retrieved account", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to cache retrieved account", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return account;
|
||||
@@ -1679,7 +1685,9 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
.thenCompose(maybeAccountFromAccounts -> maybeAccountFromAccounts
|
||||
.map(account -> redisSetAsync(account)
|
||||
.exceptionally(ExceptionUtils.exceptionallyHandler(RedisException.class, e -> {
|
||||
logger.warn("Failed to cache retrieved account", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to cache retrieved account", e);
|
||||
}
|
||||
return null;
|
||||
}))
|
||||
.thenApply(ignored -> maybeAccountFromAccounts))
|
||||
@@ -1697,7 +1705,9 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
logger.warn("Deserialization error", e);
|
||||
return Optional.empty();
|
||||
} catch (RedisException e) {
|
||||
logger.warn("Failed fetching account from cache by secondary key", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed fetching account from cache by secondary key", e);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
});
|
||||
@@ -1715,7 +1725,9 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
}
|
||||
})
|
||||
.exceptionally(throwable -> {
|
||||
logger.warn("Failed to retrieve account from Redis", throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
logger.warn("Failed to retrieve account from Redis", throwable);
|
||||
}
|
||||
return Optional.empty();
|
||||
})
|
||||
.whenComplete((_, _) -> sample.stop(timer))
|
||||
@@ -1729,7 +1741,9 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
|
||||
return parseAccountJson(json, uuid);
|
||||
} catch (final RedisException e) {
|
||||
logger.warn("Failed to retrieve account from cache", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to retrieve account from cache", e);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
});
|
||||
@@ -1739,7 +1753,9 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
return cacheCluster.withCluster(connection -> connection.async().get(getAccountEntityKey(uuid)))
|
||||
.thenApply(accountJson -> parseAccountJson(accountJson, uuid))
|
||||
.exceptionally(throwable -> {
|
||||
logger.warn("Failed to retrieve account from Redis", throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
logger.warn("Failed to retrieve account from Redis", throwable);
|
||||
}
|
||||
return Optional.empty();
|
||||
})
|
||||
.toCompletableFuture();
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.whispersystems.textsecuregcm.entities.MessageProtos;
|
||||
import org.whispersystems.textsecuregcm.identity.ServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
|
||||
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisClusterClient;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.Pair;
|
||||
import org.whispersystems.textsecuregcm.util.ResilienceUtil;
|
||||
import org.whispersystems.textsecuregcm.util.UUIDUtil;
|
||||
@@ -400,7 +401,11 @@ public class MessagesCache {
|
||||
.subscribe(messageGuids ->
|
||||
remove(destinationUuid, destinationDevice, messageGuids)
|
||||
.thenAccept(removedMessages -> counter.increment(removedMessages.size())),
|
||||
e -> logger.warn("Could not remove stale {} messages from cache", context, e));
|
||||
e -> {
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Could not remove stale {} messages from cache", context, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -524,7 +529,9 @@ public class MessagesCache {
|
||||
// MRM data) fails after it has been delivered. We return it so that it may be discarded from the queue.
|
||||
result = Mono.just(mrmMessage.toBuilder().setSharedMrmKey(STALE_MRM_KEY).build());
|
||||
} else {
|
||||
logger.warn("Failed to retrieve shared mrm data", throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
logger.warn("Failed to retrieve shared mrm data", throwable);
|
||||
}
|
||||
// For unexpected errors, return empty. The message will remain in the queue and be retried in the future.
|
||||
result = Mono.empty();
|
||||
}
|
||||
@@ -555,7 +562,9 @@ public class MessagesCache {
|
||||
REMOVE_MRM_RECIPIENT_VIEW_CONCURRENCY)
|
||||
.doOnNext(sharedMrmDataKeyRemovedCounter::increment)
|
||||
.onErrorResume(e -> {
|
||||
logger.warn("Error removing recipient view", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Error removing recipient view", e);
|
||||
}
|
||||
return Mono.just(0L);
|
||||
})
|
||||
.then()
|
||||
|
||||
+12
-6
@@ -139,10 +139,12 @@ public class MessagesManager {
|
||||
Metrics.counter(INSERT_FDB_EXCEPTIONS_COUNTER_NAME, "code", String.valueOf(fdbException.getCode()))
|
||||
.increment();
|
||||
} else {
|
||||
logger.warn("Failed to insert {} message(s) for {} into FoundationDB",
|
||||
minimizedMessagesByDeviceId.size(),
|
||||
accountIdentifier,
|
||||
e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to insert {} message(s) for {} into FoundationDB",
|
||||
minimizedMessagesByDeviceId.size(),
|
||||
accountIdentifier,
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
throw ExceptionUtils.wrap(e);
|
||||
@@ -337,7 +339,9 @@ public class MessagesManager {
|
||||
try {
|
||||
foundationDbMessageStore.clearAll(new AciServiceIdentifier(destinationUuid));
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to clear messages for {}", destinationUuid, e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to clear messages for {}", destinationUuid, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -351,7 +355,9 @@ public class MessagesManager {
|
||||
try {
|
||||
foundationDbMessageStore.clearAll(new AciServiceIdentifier(destinationUuid), deviceId);
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to clear messages for {}:{}", destinationUuid, deviceId, e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to clear messages for {}:{}", destinationUuid, deviceId, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+17
-4
@@ -9,6 +9,7 @@ import com.apple.foundationdb.FDBException;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.protobuf.CodedOutputStream;
|
||||
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.DistributionSummary;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
@@ -132,6 +133,9 @@ public class MirroringMessageStream implements MessageStream {
|
||||
protected void hookOnError(final Throwable throwable) {
|
||||
switch (ExceptionUtils.unwrap(throwable)) {
|
||||
case ConflictingMessageConsumerException _ -> CONFLICTING_CONSUMER_COUNTER.increment();
|
||||
case CallNotPermittedException _ -> {
|
||||
// CallNotPermittedExceptions are already instrumented by metrics, so do nothing
|
||||
}
|
||||
case FDBException _ -> {
|
||||
// FDBExceptions are already instrumented by metrics, so do nothing
|
||||
}
|
||||
@@ -178,6 +182,11 @@ public class MirroringMessageStream implements MessageStream {
|
||||
return JdkFlowAdapter.publisherToFlowPublisher(
|
||||
JdkFlowAdapter.flowPublisherToFlux(redisDynamoDbMessageStream.getMessages())
|
||||
.doOnNext(subscriber::handleRedisDynamoDbMessageStreamEntry)
|
||||
.doOnError(throwable -> {
|
||||
if (ExceptionUtils.unwrap(throwable) instanceof ConflictingMessageConsumerException) {
|
||||
CONFLICTING_CONSUMER_COUNTER.increment();
|
||||
}
|
||||
})
|
||||
.doFinally(_ -> {
|
||||
try {
|
||||
subscriber.dispose();
|
||||
@@ -210,16 +219,20 @@ public class MirroringMessageStream implements MessageStream {
|
||||
})
|
||||
.whenComplete((_, throwable) -> {
|
||||
if (throwable != null) {
|
||||
logger.warn("Failed to delete message {}/{}/{} from FoundationDb", accountIdentifier.uuid(), deviceId,
|
||||
messageGuid, throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
logger.warn("Failed to delete message {}/{}/{} from FoundationDb", accountIdentifier.uuid(), deviceId,
|
||||
messageGuid, throwable);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
foundationDbMessageStream.acknowledgeMessage(messageGuid, serverTimestamp)
|
||||
.whenComplete((_, throwable) -> {
|
||||
if (throwable != null) {
|
||||
logger.warn("Failed to delete message {}/{}/{} from FoundationDb", accountIdentifier.uuid(), deviceId,
|
||||
messageGuid, throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
logger.warn("Failed to delete message {}/{}/{} from FoundationDb", accountIdentifier.uuid(), deviceId,
|
||||
messageGuid, throwable);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+13
-4
@@ -27,6 +27,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.redis.ClusterLuaScript;
|
||||
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisClusterClient;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.ResilienceUtil;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
@@ -177,7 +178,9 @@ public class ProfilesManager {
|
||||
try {
|
||||
profile.ifPresent(versionedProfile -> redisSet(uuid, null, versionedProfile));
|
||||
} catch (RedisException e) {
|
||||
logger.warn("Failed to cache retrieved profile", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to cache retrieved profile", e);
|
||||
}
|
||||
}
|
||||
|
||||
return profile;
|
||||
@@ -190,7 +193,9 @@ public class ProfilesManager {
|
||||
try {
|
||||
profile.ifPresent(versionedProfile -> redisSet(uuid, versionedProfile, null));
|
||||
} catch (RedisException e) {
|
||||
logger.warn("Failed to cache retrieved profile", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to cache retrieved profile", e);
|
||||
}
|
||||
}
|
||||
|
||||
return profile;
|
||||
@@ -239,7 +244,9 @@ public class ProfilesManager {
|
||||
|
||||
return parseProfileJson(json, VersionedProfile.class);
|
||||
} catch (RedisException e) {
|
||||
logger.warn("Redis exception", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Redis exception", e);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -255,7 +262,9 @@ public class ProfilesManager {
|
||||
|
||||
return parseProfileJson(json, VersionedProfileV1.class);
|
||||
} catch (RedisException e) {
|
||||
logger.warn("Failed to retrieve profile from cache", e);
|
||||
if (!ExceptionUtils.isBreakerOpen(e)) {
|
||||
logger.warn("Failed to retrieve profile from cache", e);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -451,7 +451,9 @@ class FoundationDbMessagePublisher {
|
||||
final ScheduledFuture<?> scheduledFuture = presenceRenewalExecutorService.schedule(() -> {
|
||||
renewPresence().whenComplete((_, throwable) -> {
|
||||
if (throwable != null) {
|
||||
LOGGER.warn("Failed to renew presence", throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
LOGGER.warn("Failed to renew presence", throwable);
|
||||
}
|
||||
renewPresenceFuture.completeExceptionally(throwable);
|
||||
} else {
|
||||
renewPresenceFuture.complete(null);
|
||||
@@ -503,7 +505,7 @@ class FoundationDbMessagePublisher {
|
||||
}
|
||||
}), FaultTolerantDatabase.Context.CLEAR_PRESENCE)
|
||||
.whenComplete((_, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable != null && !ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
LOGGER.warn("Failed to clear presence on disposal", throwable);
|
||||
}
|
||||
}));
|
||||
|
||||
+7
-2
@@ -50,6 +50,7 @@ import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.metrics.DevicePlatformUtil;
|
||||
import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.Pair;
|
||||
import org.whispersystems.textsecuregcm.util.UUIDUtil;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
@@ -720,7 +721,9 @@ public class FoundationDbMessageStore {
|
||||
|
||||
return deleteModifier.apply(deleteMono)
|
||||
.onErrorResume(throwable -> {
|
||||
LOGGER.warn("Failed to trim message queue for {}:{}", aci, device.getId(), throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
LOGGER.warn("Failed to trim message queue for {}:{}", aci, device.getId(), throwable);
|
||||
}
|
||||
return Mono.just(false);
|
||||
});
|
||||
})
|
||||
@@ -731,7 +734,9 @@ public class FoundationDbMessageStore {
|
||||
.onErrorResume(throwable -> {
|
||||
// If we error out on estimating queue size, we don't know if this queue needed trimming
|
||||
Metrics.counter(TRIM_QUEUE_COUNTER_NAME, "success", "false").increment();
|
||||
LOGGER.warn("Failed to estimate queue size for {}:{}", aci, device.getId(), throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
LOGGER.warn("Failed to estimate queue size for {}:{}", aci, device.getId(), throwable);
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
+4
-1
@@ -24,6 +24,7 @@ import org.whispersystems.textsecuregcm.entities.MessageProtos;
|
||||
import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.storage.MessageStream;
|
||||
import org.whispersystems.textsecuregcm.storage.MessageStreamEntry;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import reactor.adapter.JdkFlowAdapter;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -215,7 +216,9 @@ public class FoundationDbMessageStream implements MessageStream {
|
||||
})
|
||||
.whenComplete((_, throwable) -> {
|
||||
if (throwable != null) {
|
||||
logger.warn("Failed to fetch end-of-queue key", throwable);
|
||||
if (!ExceptionUtils.isBreakerOpen(throwable)) {
|
||||
logger.warn("Failed to fetch end-of-queue key", throwable);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+9
-4
@@ -9,6 +9,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpRequest;
|
||||
@@ -19,15 +22,13 @@ import java.util.Optional;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.annotation.Nullable;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.whispersystems.textsecuregcm.http.FaultTolerantHttpClient;
|
||||
import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
|
||||
import org.whispersystems.textsecuregcm.telephony.CarrierData;
|
||||
import org.whispersystems.textsecuregcm.telephony.CarrierDataException;
|
||||
import org.whispersystems.textsecuregcm.telephony.CarrierDataProvider;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
|
||||
/// A carrier data provider that uses [HLR Lookup](https://www.hlrlookup.com/) as its data source.
|
||||
@@ -117,10 +118,14 @@ public class HlrLookupCarrierDataProvider implements CarrierDataProvider {
|
||||
|
||||
Metrics.counter(REQUEST_COUNTER_NAME, "status", String.valueOf(httpResponse.statusCode()))
|
||||
.increment();
|
||||
} catch (final IOException | CarrierDataException e) {
|
||||
} catch (final IOException | CarrierDataException | RuntimeException e) {
|
||||
Metrics.counter(REQUEST_COUNTER_NAME, "exception", e.getClass().getSimpleName())
|
||||
.increment();
|
||||
|
||||
if (ExceptionUtils.isBreakerOpen(e)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class ExceptionUtils {
|
||||
|
||||
@@ -127,4 +129,19 @@ public final class ExceptionUtils {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks whether an exception in the chain is a [CallNotPermittedException].
|
||||
///
|
||||
/// This is useful to check when logging, to avoid repetitive output.
|
||||
public static boolean isBreakerOpen(@Nullable Throwable t) {
|
||||
if (t == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (!(t instanceof CallNotPermittedException) && t.getCause() != null) {
|
||||
t = t.getCause();
|
||||
}
|
||||
|
||||
return t instanceof CallNotPermittedException;
|
||||
}
|
||||
}
|
||||
+11
@@ -9,9 +9,12 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
import io.dropwizard.jersey.errors.LoggingExceptionMapper;
|
||||
import jakarta.inject.Provider;
|
||||
import jakarta.ws.rs.WebApplicationException;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.glassfish.jersey.server.ContainerRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.ua.UnrecognizedUserAgentException;
|
||||
import org.whispersystems.textsecuregcm.util.ua.UserAgent;
|
||||
import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil;
|
||||
@@ -33,6 +36,14 @@ public class LoggingUnhandledExceptionMapper extends LoggingExceptionMapper<Thro
|
||||
super(logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response toResponse(final Throwable exception) {
|
||||
if (!(exception instanceof WebApplicationException) && ExceptionUtils.isBreakerOpen(exception)) {
|
||||
return Response.status(Response.Status.SERVICE_UNAVAILABLE).build();
|
||||
}
|
||||
return super.toResponse(exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String formatLogMessage(final long id, final Throwable exception) {
|
||||
String requestMethod = "unknown method";
|
||||
|
||||
+3
-2
@@ -20,11 +20,9 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import javax.annotation.Nullable;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.jetty.util.ConstantThrowable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -45,6 +43,7 @@ import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.MessageStream;
|
||||
import org.whispersystems.textsecuregcm.storage.MessageStreamEntry;
|
||||
import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.HeaderUtils;
|
||||
import org.whispersystems.textsecuregcm.util.UUIDUtil;
|
||||
import org.whispersystems.textsecuregcm.util.ua.UserAgent;
|
||||
@@ -289,6 +288,8 @@ public class WebSocketConnection {
|
||||
errorType = "timeout";
|
||||
} else if (isConnectionClosedException(e)) {
|
||||
errorType = "connectionClosed";
|
||||
} else if (ExceptionUtils.isBreakerOpen(e)) {
|
||||
errorType = "breakerOpen";
|
||||
} else {
|
||||
logger.warn("Send message failed", e);
|
||||
errorType = "other";
|
||||
|
||||
+4
-1
@@ -42,6 +42,7 @@ import org.whispersystems.textsecuregcm.storage.AccountLockManager;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.foundationdb.FaultTolerantDatabase;
|
||||
import org.whispersystems.textsecuregcm.storage.foundationdb.FoundationDbMessageStore;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.ManagedExecutors;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -191,7 +192,9 @@ public class ClearOrphanedFoundationDbQueuesCommand extends AbstractCommandWithD
|
||||
accountLockManager, scheduler)
|
||||
.thenReturn(true)
|
||||
.onErrorResume(t -> {
|
||||
logger.error("Failed to clear orphaned queue for ACI: {}", aci.uuid(), t);
|
||||
if (!ExceptionUtils.isBreakerOpen(t)) {
|
||||
logger.error("Failed to clear orphaned queue for ACI: {}", aci.uuid(), t);
|
||||
}
|
||||
return Mono.just(false);
|
||||
});
|
||||
})
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2026 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
|
||||
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
class ExceptionUtilsTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void isBreakerOpen(final Throwable t, final boolean expected) {
|
||||
assertEquals(expected, ExceptionUtils.isBreakerOpen(t));
|
||||
}
|
||||
|
||||
static Collection<Arguments> isBreakerOpen() {
|
||||
final CircuitBreaker breaker = CircuitBreaker.ofDefaults("test");
|
||||
final CallNotPermittedException callNotPermittedException =
|
||||
CallNotPermittedException.createCallNotPermittedException(breaker);
|
||||
return List.of(
|
||||
Arguments.argumentSet("simple - present", callNotPermittedException, true),
|
||||
Arguments.argumentSet("nested - present", new CompletionException(callNotPermittedException), true),
|
||||
Arguments.argumentSet("deep - present", new CompletionException(new IOException(callNotPermittedException)),
|
||||
true),
|
||||
|
||||
Arguments.argumentSet("null", null, false),
|
||||
Arguments.argumentSet("simple - absent", new RuntimeException(), false),
|
||||
Arguments.argumentSet("nested - absent", new CompletionException(new RuntimeException()), false),
|
||||
Arguments.argumentSet("deep - absent", new CompletionException(new IOException(new RuntimeException())), false)
|
||||
);
|
||||
}
|
||||
}
|
||||
+50
@@ -6,6 +6,7 @@
|
||||
package org.whispersystems.textsecuregcm.util.logging;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.matches;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -21,13 +22,19 @@ import io.dropwizard.jersey.DropwizardResourceConfig;
|
||||
import io.dropwizard.jersey.jackson.JacksonMessageBodyProvider;
|
||||
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
|
||||
import io.dropwizard.testing.junit5.ResourceExtension;
|
||||
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
|
||||
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
|
||||
import io.lettuce.core.RedisException;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.ServerErrorException;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -39,6 +46,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
import org.eclipse.jetty.websocket.api.Callback;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
@@ -162,6 +170,30 @@ class LoggingUnhandledExceptionMapperTest {
|
||||
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void testBreakerExceptions(final String path, @Nullable final Boolean isBreaker, final boolean expectLog) {
|
||||
resources.getJerseyTest()
|
||||
.target(path)
|
||||
.queryParam("breaker", isBreaker)
|
||||
.request()
|
||||
.get();
|
||||
|
||||
if (expectLog) {
|
||||
verifyNoInteractions(logger);
|
||||
} else {
|
||||
verify(logger).error(anyString(), any(Throwable.class));
|
||||
}
|
||||
}
|
||||
|
||||
static Collection<Arguments> testBreakerExceptions() {
|
||||
return List.of(
|
||||
Arguments.argumentSet("redis wraps breaker", "/v1/test/redis-exception", true, true),
|
||||
Arguments.argumentSet("redis wraps other", "/v1/test/redis-exception", false, false),
|
||||
Arguments.argumentSet("WebApplicationException wraps breaker", "/v1/test/webapplication-exception-wraps-breaker", null, false)
|
||||
);
|
||||
}
|
||||
|
||||
private WebSocketResourceProvider<TestPrincipal> createWebsocketProvider(final String userAgentHeader,
|
||||
final Session session, final Consumer<ByteBuffer> responseHandler) throws IOException {
|
||||
ResourceConfig resourceConfig = new DropwizardResourceConfig();
|
||||
@@ -200,6 +232,24 @@ class LoggingUnhandledExceptionMapperTest {
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/redis-exception")
|
||||
public Response testRedisException(@QueryParam("breaker") final boolean isBreaker) {
|
||||
final Throwable cause = isBreaker ? CallNotPermittedException.createCallNotPermittedException(
|
||||
CircuitBreaker.ofDefaults(LoggingUnhandledExceptionMapperTest.class.getSimpleName()))
|
||||
: new IOException("oh no");
|
||||
|
||||
throw new RedisException(cause);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/webapplication-exception-wraps-breaker")
|
||||
public Response testWebApplicationExceptionWrapsBreaker() {
|
||||
throw new ServerErrorException(Response.Status.BAD_GATEWAY,
|
||||
CallNotPermittedException.createCallNotPermittedException(
|
||||
CircuitBreaker.ofDefaults(LoggingUnhandledExceptionMapperTest.class.getSimpleName())));
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/unhandled-runtime-exception")
|
||||
public Response testUnhandledException() {
|
||||
|
||||
Reference in new issue
Block a user