protected void stopAllPipesWithCriticalException(final int currentNodeId) {
    // To avoid deadlock, we use a new thread to stop all pipes.
    CompletableFuture.runAsync(
        () -> {
          try {
            int retryCount = 0;
            while (true) {
              if (tryWriteLockWithTimeOut(5)) {
                try {
                  stopAllPipesWithCriticalExceptionInternal(currentNodeId);
                  LOGGER.info("Stopped all pipes with critical exception.");
                  return;
                } finally {
                  releaseWriteLock();
                }
              } else {
                Thread.sleep(1000);
                LOGGER.warn(
                    "Failed to stop all pipes with critical exception, retry count: {}.",
                    ++retryCount);
              }
            }
          } catch (final InterruptedException e) {
            LOGGER.error(
                "Interrupted when trying to stop all pipes with critical exception, exception message: {}",
                e.getMessage(),
                e);
            Thread.currentThread().interrupt();
          } catch (final Exception e) {
            LOGGER.error(
                "Failed to stop all pipes with critical exception, exception message: {}",
                e.getMessage(),
                e);
          }
        });
  }
Using try lock method to prevent deadlock when stopping all pipes with critical exceptions and
{@link PipeTaskAgent#handlePipeMetaChanges(List)}} concurrently.
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/task/PipeTaskAgent.java