Use static exception instance when a connection is closed
This commit is contained in:
parent
8348263fab
commit
92bb783cbb
|
@ -53,6 +53,7 @@ import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
|||
import org.whispersystems.textsecuregcm.util.Constants;
|
||||
import org.whispersystems.textsecuregcm.util.HeaderUtils;
|
||||
import org.whispersystems.websocket.WebSocketClient;
|
||||
import org.whispersystems.websocket.WebSocketResourceProvider;
|
||||
import org.whispersystems.websocket.messages.WebSocketResponseMessage;
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.observability.micrometer.Micrometer;
|
||||
|
@ -395,6 +396,8 @@ public class WebSocketConnection implements MessageAvailabilityListener, Displac
|
|||
errorType = "timeout";
|
||||
} else if (e instanceof java.nio.channels.ClosedChannelException) {
|
||||
errorType = "closedChannel";
|
||||
} else if (e == WebSocketResourceProvider.CONNECTION_CLOSED_EXCEPTION) {
|
||||
errorType = "connectionClosed";
|
||||
} else {
|
||||
logger.warn(terminal ? "Send message failure terminated stream" : "Send message failed", e);
|
||||
errorType = "other";
|
||||
|
|
|
@ -47,6 +47,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
public class WebSocketResourceProvider<T extends Principal> implements WebSocketListener {
|
||||
|
||||
/**
|
||||
* A static exception instance passed to outstanding requests (via {@code completeExceptionally} in
|
||||
* {@link #onWebSocketClose(int, String)}
|
||||
*/
|
||||
public static final IOException CONNECTION_CLOSED_EXCEPTION = new IOException("Connection closed!");
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketResourceProvider.class);
|
||||
|
||||
private final Map<Long, CompletableFuture<WebSocketResponseMessage>> requestMap = new ConcurrentHashMap<>();
|
||||
|
@ -141,7 +146,7 @@ public class WebSocketResourceProvider<T extends Principal> implements WebSocket
|
|||
CompletableFuture<WebSocketResponseMessage> outstandingRequest = requestMap.remove(requestId);
|
||||
|
||||
if (outstandingRequest != null) {
|
||||
outstandingRequest.completeExceptionally(new IOException("Connection closed!"));
|
||||
outstandingRequest.completeExceptionally(CONNECTION_CLOSED_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue