Browse Source

Unblock and interrupt edge event consumer on session destroy

pull/16004/head
Nikita Mazurenko 4 weeks ago
parent
commit
6de4b30e5f
  1. 2
      application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java
  2. 7
      application/src/main/java/org/thingsboard/server/service/edge/rpc/KafkaEdgeGrpcSession.java

2
application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java

@ -760,7 +760,7 @@ public abstract class EdgeGrpcSession implements Closeable {
ctx.getClusterService().onEdgeEventUpdate(new EdgeEventUpdateMsg(edge.getTenantId(), edge.getId())); ctx.getClusterService().onEdgeEventUpdate(new EdgeEventUpdateMsg(edge.getTenantId(), edge.getId()));
} }
private void stopCurrentSendDownlinkMsgsTask(Boolean isInterrupted) { protected void stopCurrentSendDownlinkMsgsTask(Boolean isInterrupted) {
if (sessionState.getSendDownlinkMsgsFuture() != null && !sessionState.getSendDownlinkMsgsFuture().isDone()) { if (sessionState.getSendDownlinkMsgsFuture() != null && !sessionState.getSendDownlinkMsgsFuture().isDone()) {
sessionState.getSendDownlinkMsgsFuture().set(isInterrupted); sessionState.getSendDownlinkMsgsFuture().set(isInterrupted);
} }

7
application/src/main/java/org/thingsboard/server/service/edge/rpc/KafkaEdgeGrpcSession.java

@ -156,6 +156,7 @@ public class KafkaEdgeGrpcSession extends EdgeGrpcSession {
@Override @Override
public boolean destroy() { public boolean destroy() {
stopCurrentSendDownlinkMsgsTask(true);
try { try {
if (consumer != null) { if (consumer != null) {
log.info("[{}][{}] Stopping edge event consumer...", tenantId, edge != null ? edge.getId() : null); log.info("[{}][{}] Stopping edge event consumer...", tenantId, edge != null ? edge.getId() : null);
@ -180,9 +181,13 @@ public class KafkaEdgeGrpcSession extends EdgeGrpcSession {
private void awaitConsumerTermination() { private void awaitConsumerTermination() {
try { try {
consumerExecutor.awaitTermination(5, java.util.concurrent.TimeUnit.SECONDS); if (!consumerExecutor.awaitTermination(5, java.util.concurrent.TimeUnit.SECONDS)) {
// without this the thread is leaked for the whole remaining delivery-retry window (or forever, if the future is never completed).
consumerExecutor.shutdownNow();
}
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
log.warn("[{}][{}] Interrupted while awaiting consumer executor termination", tenantId, edge.getId()); log.warn("[{}][{}] Interrupted while awaiting consumer executor termination", tenantId, edge.getId());
Thread.currentThread().interrupt();
} }
} }

Loading…
Cancel
Save