Skip to content

Commit c155666

Browse files
authored
Pipe: Fixed the OPC UA bug that drop pipe may not erase the client (#17510) (#17522)
1 parent 413b074 commit c155666

1 file changed

Lines changed: 26 additions & 30 deletions

File tree

  • iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaSink.java

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -518,42 +518,38 @@ public interface ThrowingConsumer<T, E extends Exception> {
518518

519519
@Override
520520
public void close() throws Exception {
521-
if (serverKey == null) {
522-
return;
523-
}
524-
525-
synchronized (SERVER_KEY_TO_REFERENCE_COUNT_AND_NAME_SPACE_MAP) {
526-
final Pair<AtomicInteger, OpcUaNameSpace> pair =
527-
SERVER_KEY_TO_REFERENCE_COUNT_AND_NAME_SPACE_MAP.get(serverKey);
528-
if (pair == null) {
529-
return;
530-
}
521+
if (serverKey != null) {
522+
synchronized (SERVER_KEY_TO_REFERENCE_COUNT_AND_NAME_SPACE_MAP) {
523+
final Pair<AtomicInteger, OpcUaNameSpace> pair =
524+
SERVER_KEY_TO_REFERENCE_COUNT_AND_NAME_SPACE_MAP.get(serverKey);
525+
if (pair == null) {
526+
return;
527+
}
531528

532-
if (pair.getLeft().decrementAndGet() <= 0) {
533-
try {
534-
pair.getRight().shutdown();
535-
} finally {
536-
SERVER_KEY_TO_REFERENCE_COUNT_AND_NAME_SPACE_MAP.remove(serverKey);
529+
if (pair.getLeft().decrementAndGet() <= 0) {
530+
try {
531+
pair.getRight().shutdown();
532+
} finally {
533+
SERVER_KEY_TO_REFERENCE_COUNT_AND_NAME_SPACE_MAP.remove(serverKey);
534+
}
537535
}
538536
}
539537
}
540538

541-
if (nodeUrl == null) {
542-
return;
543-
}
544-
545-
synchronized (CLIENT_KEY_TO_REFERENCE_COUNT_AND_CLIENT_MAP) {
546-
final Pair<AtomicInteger, IoTDBOpcUaClient> pair =
547-
CLIENT_KEY_TO_REFERENCE_COUNT_AND_CLIENT_MAP.get(nodeUrl);
548-
if (pair == null) {
549-
return;
550-
}
539+
if (nodeUrl != null) {
540+
synchronized (CLIENT_KEY_TO_REFERENCE_COUNT_AND_CLIENT_MAP) {
541+
final Pair<AtomicInteger, IoTDBOpcUaClient> pair =
542+
CLIENT_KEY_TO_REFERENCE_COUNT_AND_CLIENT_MAP.get(nodeUrl);
543+
if (pair == null) {
544+
return;
545+
}
551546

552-
if (pair.getLeft().decrementAndGet() <= 0) {
553-
try {
554-
pair.getRight().disconnect();
555-
} finally {
556-
CLIENT_KEY_TO_REFERENCE_COUNT_AND_CLIENT_MAP.remove(nodeUrl);
547+
if (pair.getLeft().decrementAndGet() <= 0) {
548+
try {
549+
pair.getRight().disconnect();
550+
} finally {
551+
CLIENT_KEY_TO_REFERENCE_COUNT_AND_CLIENT_MAP.remove(nodeUrl);
552+
}
557553
}
558554
}
559555
}

0 commit comments

Comments
 (0)