mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 01:06:50 +00:00
Add marker for unexpected error logs
This commit is contained in:
1 parent
07444bffb4
commit
02d6138848
13 files changed
+91
-12
No files matched your search
@@ -204,6 +204,7 @@ import org.whispersystems.textsecuregcm.mappers.CompletionExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.DeviceLimitExceededExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.GrpcStatusRuntimeExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.IOExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.IllegalStateExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.ImpossiblePhoneNumberExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.InvalidWebsocketAddressExceptionMapper;
|
||||
import org.whispersystems.textsecuregcm.mappers.JsonMappingExceptionMapper;
|
||||
@@ -1343,6 +1344,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||
new InvalidWebsocketAddressExceptionMapper(),
|
||||
new DeviceLimitExceededExceptionMapper(),
|
||||
new ServerRejectedExceptionMapper(),
|
||||
new IllegalStateExceptionMapper(),
|
||||
new ImpossiblePhoneNumberExceptionMapper(),
|
||||
new NonNormalizedPhoneNumberExceptionMapper(),
|
||||
new ObsoletePhoneNumberFormatExceptionMapper(),
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.grpc.RequestAttributesUtil;
|
||||
import org.whispersystems.textsecuregcm.util.InetAddressRange;
|
||||
import org.whispersystems.textsecuregcm.util.logging.ImpossibleEvents;
|
||||
|
||||
public class ExternalRequestFilter implements Filter, ServerInterceptor {
|
||||
|
||||
@@ -85,7 +86,7 @@ public class ExternalRequestFilter implements Filter, ServerInterceptor {
|
||||
if (response instanceof HttpServletResponse hsr) {
|
||||
hsr.setStatus(404);
|
||||
} else {
|
||||
logger.warn("response was an unexpected type: {}", response.getClass());
|
||||
ImpossibleEvents.logImpossible(logger, "response was an unexpected type: {}", response.getClass());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ import java.io.IOException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.util.HttpServletRequestUtil;
|
||||
import org.whispersystems.textsecuregcm.util.logging.ImpossibleEvents;
|
||||
|
||||
/**
|
||||
* Sets a {@link HttpServletRequest} attribute (that will also be available as a
|
||||
@@ -36,7 +37,7 @@ public class RemoteAddressFilter implements Filter {
|
||||
request.setAttribute(REMOTE_ADDRESS_ATTRIBUTE_NAME, remoteAddress);
|
||||
|
||||
} else {
|
||||
logger.warn("request was of unexpected type: {}", request.getClass());
|
||||
ImpossibleEvents.logImpossible(logger, "request was of unexpected type: {}", request.getClass());
|
||||
}
|
||||
|
||||
chain.doFilter(request, response);
|
||||
|
||||
+5
@@ -15,6 +15,7 @@ import io.grpc.StatusRuntimeException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.logging.ImpossibleEvents;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
@@ -59,6 +60,10 @@ public class ErrorMappingInterceptor implements ServerInterceptor {
|
||||
log.warn("RPC {} encountered IOException", call.getMethodDescriptor().getFullMethodName(), e);
|
||||
yield GrpcExceptions.unavailable();
|
||||
}
|
||||
case IllegalStateException e -> {
|
||||
ImpossibleEvents.logImpossible(log, e.getMessage(), e);
|
||||
yield GrpcExceptions.unavailable(e.getMessage());
|
||||
}
|
||||
case null -> {
|
||||
log.error("RPC {} finished with status UNKNOWN: {}",
|
||||
call.getMethodDescriptor().getFullMethodName(), status.getDescription());
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2026 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.mappers;
|
||||
|
||||
import io.dropwizard.jersey.errors.ErrorMessage;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.util.logging.ImpossibleEvents;
|
||||
|
||||
@Provider
|
||||
public class IllegalStateExceptionMapper implements ExceptionMapper<IllegalStateException> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(IllegalStateExceptionMapper.class);
|
||||
|
||||
@Override
|
||||
public Response toResponse(final IllegalStateException exception) {
|
||||
ImpossibleEvents.logImpossible(logger, exception.getMessage(), exception);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||
.entity(new ErrorMessage(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
"There was an internal server error processing your request"))
|
||||
.type(MediaType.APPLICATION_JSON_TYPE)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -389,10 +389,9 @@ public class Accounts {
|
||||
writeItems.add(buildDelete(phoneNumberConstraintTableName, ATTR_ACCOUNT_E164, existingAccount.getNumber()));
|
||||
writeItems.add(phoneNumberConstraintPut);
|
||||
} else {
|
||||
log.error("Reclaiming account with a non-equivalent phone number. Old account {}:{}:{}, new account {}:{}:{}",
|
||||
throw new IllegalStateException(String.format("Reclaiming account with a non-equivalent phone number. Old account %s:%s:%s, new account %s:%s:%s",
|
||||
existingAccount.getUuid(), redactPhoneNumber(existingAccount.getNumber()), existingAccount.getPhoneNumberIdentifier(),
|
||||
accountToCreate.getUuid(), redactPhoneNumber(accountToCreate.getNumber()), accountToCreate.getPhoneNumberIdentifier());
|
||||
throw new IllegalArgumentException("reclaimed accounts must have equivalent phone numbers");
|
||||
accountToCreate.getUuid(), redactPhoneNumber(accountToCreate.getNumber()), accountToCreate.getPhoneNumberIdentifier()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ import org.whispersystems.textsecuregcm.util.ResilienceUtil;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
import org.whispersystems.textsecuregcm.util.ThrowingConsumer;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
import org.whispersystems.textsecuregcm.util.logging.ImpossibleEvents;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
import software.amazon.awssdk.services.dynamodb.model.TransactWriteItem;
|
||||
@@ -1634,7 +1635,7 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
channel.substring(TRANSFER_ARCHIVE_KEYSPACE_PATTERN.length() - 1).split(":", 4);
|
||||
|
||||
if (deviceIdentifierComponents.length != 4) {
|
||||
logger.error("Could not parse device identifier; unexpected component count: {}",
|
||||
ImpossibleEvents.logImpossible(logger, "Could not parse device identifier; unexpected component count: {}",
|
||||
deviceIdentifierComponents.length);
|
||||
return;
|
||||
}
|
||||
|
||||
+6
@@ -44,6 +44,7 @@ import org.whispersystems.textsecuregcm.push.MessageSender;
|
||||
import org.whispersystems.textsecuregcm.push.MessageTooLargeException;
|
||||
import org.whispersystems.textsecuregcm.util.Pair;
|
||||
import org.whispersystems.textsecuregcm.util.UUIDUtil;
|
||||
import org.whispersystems.textsecuregcm.util.logging.ImpossibleEvents;
|
||||
|
||||
public class ChangeNumberManager {
|
||||
|
||||
@@ -174,6 +175,11 @@ public class ChangeNumberManager {
|
||||
registrationIdsByDeviceId,
|
||||
Optional.of(Device.PRIMARY_ID),
|
||||
userAgent);
|
||||
} catch (MismatchedDevicesException | MessageTooLargeException e) {
|
||||
ImpossibleEvents.logImpossible(logger,
|
||||
"Changed number but could not send device messages after preliminary validation succeeded {}",
|
||||
account.getIdentifier(IdentityType.ACI), e);
|
||||
throw e;
|
||||
} catch (final RuntimeException e) {
|
||||
logger.warn("Changed number but could not send all device messages for {}",
|
||||
account.getIdentifier(IdentityType.ACI), e);
|
||||
|
||||
+4
-3
@@ -30,6 +30,7 @@ import org.whispersystems.textsecuregcm.entities.KEMSignedPreKey;
|
||||
import org.whispersystems.textsecuregcm.util.AttributeValues;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
import org.whispersystems.textsecuregcm.util.logging.ImpossibleEvents;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import software.amazon.awssdk.core.async.AsyncRequestBody;
|
||||
@@ -245,7 +246,7 @@ public class PagedSingleUseKEMPreKeyStore {
|
||||
final int numKeys = AttributeValues.getInt(getResponse.item(), ATTR_PAGE_NUM_KEYS, -1);
|
||||
final int index = AttributeValues.getInt(getResponse.item(), ATTR_PAGE_IDX, -1);
|
||||
if (numKeys < 0 || index < 0 || index > numKeys) {
|
||||
log.error("unexpected index/length in page descriptor: {}", getResponse.item());
|
||||
ImpossibleEvents.logImpossible(log, "unexpected index/length in page descriptor: {}", getResponse.item());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -355,7 +356,7 @@ public class PagedSingleUseKEMPreKeyStore {
|
||||
final byte deviceId = (byte) AttributeValues.getInt(item, KEY_DEVICE_ID, -1);
|
||||
final UUID pageId = AttributeValues.getUUID(item, ATTR_PAGE_ID, null);
|
||||
if (aci == null || deviceId < 0 || pageId == null) {
|
||||
log.error("can't delete page from unexpected page descriptor {}", item);
|
||||
ImpossibleEvents.logImpossible(log, "can't delete page from unexpected page descriptor {}", item);
|
||||
}
|
||||
return Mono.fromFuture(deleteBundleFromS3(aci, deviceId, pageId))
|
||||
.thenReturn(Map.of(
|
||||
@@ -429,7 +430,7 @@ public class PagedSingleUseKEMPreKeyStore {
|
||||
.thenApply(bytes -> {
|
||||
final ByteBuffer serialized = bytes.asByteBuffer();
|
||||
if (serialized.remaining() != keyLocation.length()) {
|
||||
log.error("Unexpected ranged read response, requested {} got {} for offset {} in page {}",
|
||||
ImpossibleEvents.logImpossible(log, "Unexpected ranged read response, requested {} got {} for offset {} in page {}",
|
||||
keyLocation.length(), serialized.remaining(), keyLocation, s3Key(identifier, deviceId, pageId));
|
||||
throw new CompletionException(new IOException("Invalid response to ranged read"));
|
||||
}
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ package org.whispersystems.textsecuregcm.subscriptions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.util.logging.ImpossibleEvents;
|
||||
|
||||
public enum SubscriptionStatus {
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ public enum SubscriptionStatus {
|
||||
|
||||
case "trialing" -> {
|
||||
final Logger logger = LoggerFactory.getLogger(CustomerAwareSubscriptionPaymentProcessor.class);
|
||||
logger.error("Subscription has status that should never happen: {}", status);
|
||||
ImpossibleEvents.logImpossible(logger, "Subscription has status that should never happen: {}", status);
|
||||
|
||||
yield UNKNOWN;
|
||||
}
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
|
||||
import org.whispersystems.textsecuregcm.util.logging.ImpossibleEvents;
|
||||
|
||||
/**
|
||||
* A thread factory that creates virtual threads but limits the total number of virtual threads created.
|
||||
@@ -87,7 +88,7 @@ public class BoundedVirtualThreadFactory implements ThreadFactory {
|
||||
private void release() {
|
||||
int updated = runningThreads.decrementAndGet();
|
||||
if (updated < 0) {
|
||||
logger.error("Released a thread and count was {}, which should never happen", updated);
|
||||
ImpossibleEvents.logImpossible(logger, "Released a thread and count was {}, which should never happen", updated);
|
||||
}
|
||||
completed.increment();
|
||||
}
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2026 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.util.logging;
|
||||
|
||||
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
||||
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import net.logstash.logback.marker.Markers;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.Marker;
|
||||
|
||||
/// Log errors that represent a programming logic error
|
||||
public final class ImpossibleEvents {
|
||||
|
||||
private static final Marker IMPOSSIBLE = Markers.append("impossible", true);
|
||||
private static final Counter COUNTER = Metrics.counter(name(ImpossibleEvents.class, "count"));
|
||||
|
||||
private ImpossibleEvents() {
|
||||
}
|
||||
|
||||
/// Log that an event should never happen.
|
||||
public static void logImpossible(final Logger logger, final String message, final Object... args) {
|
||||
COUNTER.increment();
|
||||
logger.error(IMPOSSIBLE, message, args);
|
||||
}
|
||||
}
|
||||
@@ -639,7 +639,7 @@ class AccountsTest {
|
||||
|
||||
secondAccount.setUuid(accountAlreadyExistsException.getExistingAccount().getUuid());
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> accounts.reclaimAccount(existingAccount,
|
||||
assertThrows(IllegalStateException.class, () -> accounts.reclaimAccount(existingAccount,
|
||||
secondAccount,
|
||||
Collections.emptyList()).toCompletableFuture().join());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user