mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Unsubscribe receive if jsonRpcSender channel is closed
This commit is contained in:
parent
7bf06aef5e
commit
c8cd36bde8
2 changed files with 11 additions and 2 deletions
|
@ -860,7 +860,8 @@ class ManagerImpl implements Manager {
|
||||||
logger.debug("Starting receiving messages");
|
logger.debug("Starting receiving messages");
|
||||||
context.getReceiveHelper().receiveMessagesContinuously((envelope, e) -> {
|
context.getReceiveHelper().receiveMessagesContinuously((envelope, e) -> {
|
||||||
synchronized (messageHandlers) {
|
synchronized (messageHandlers) {
|
||||||
Stream.concat(messageHandlers.stream(), weakHandlers.stream()).forEach(h -> {
|
final var handlers = Stream.concat(messageHandlers.stream(), weakHandlers.stream()).toList();
|
||||||
|
handlers.forEach(h -> {
|
||||||
try {
|
try {
|
||||||
h.handleMessage(envelope, e);
|
h.handleMessage(envelope, e);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.nio.channels.OverlappingFileLockException;
|
import java.nio.channels.OverlappingFileLockException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -101,7 +102,14 @@ public class SignalJsonRpcDispatcherHandler {
|
||||||
final var receiveMessageHandler = new JsonReceiveMessageHandler(m, s -> {
|
final var receiveMessageHandler = new JsonReceiveMessageHandler(m, s -> {
|
||||||
final ContainerNode<?> params = objectMapper.valueToTree(s);
|
final ContainerNode<?> params = objectMapper.valueToTree(s);
|
||||||
((ObjectNode) params).set("subscription", IntNode.valueOf(subscriptionId));
|
((ObjectNode) params).set("subscription", IntNode.valueOf(subscriptionId));
|
||||||
jsonRpcSender.sendRequest(JsonRpcRequest.forNotification("receive", params, null));
|
final var jsonRpcRequest = JsonRpcRequest.forNotification("receive", params, null);
|
||||||
|
try {
|
||||||
|
jsonRpcSender.sendRequest(jsonRpcRequest);
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
if (e.getCause() instanceof ClosedChannelException) {
|
||||||
|
unsubscribeReceive(subscriptionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
m.addReceiveHandler(receiveMessageHandler);
|
m.addReceiveHandler(receiveMessageHandler);
|
||||||
return new Pair<>(m, (Manager.ReceiveMessageHandler) receiveMessageHandler);
|
return new Pair<>(m, (Manager.ReceiveMessageHandler) receiveMessageHandler);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue