apache/flink · error · FlinkException

Could not close resource.

Error message

Could not close resource.

What it means

Thrown by the default close() method of AutoCloseableAsync when the CompletableFuture returned by closeAsync() completes exceptionally. The synchronous close() simply blocks on the async close and re-wraps the cause (with ExecutionException stripped) in a FlinkException.

Source

Thrown at flink-core/src/main/java/org/apache/flink/util/AutoCloseableAsync.java:38

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/** Closeable interface which allows to close a resource in a non blocking fashion. */
public interface AutoCloseableAsync extends AutoCloseable {

    /**
     * Trigger the closing of the resource and return the corresponding close future.
     *
     * @return Future which is completed once the resource has been closed
     */
    CompletableFuture<Void> closeAsync();

    default void close() throws Exception {
        try {
            closeAsync().get();
        } catch (ExecutionException e) {
            throw new FlinkException(
                    "Could not close resource.", ExceptionUtils.stripExecutionException(e));
        }
    }
}

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Inspect the suppressed cause (e.getCause()) — the real failure is the underlying closeAsync future's exception, not this message
  2. Fix the root cause in the async shutdown path (connection, timeout, state) that made the future fail
  3. In tests and teardown code, catch and log close failures separately so they do not mask the original error (or use SuppressedExceptions/Closeable#quiet close utilities)

Example fix

// before
resource.close(); // secondary failure hides the primary test failure

// after
try {
    resource.close();
} catch (Exception e) {
    LOG.warn("Failed to close {}", resource, e); // don't mask the original error
}
Defensive patterns

Strategy: try-catch

Try / catch

try { resource.close(); } catch (FlinkException e) { log cause e.getCause(); in tests, record as suppressed instead of rethrowing over the primary failure }

Prevention

When it happens

Trigger: Calling close() on components implementing AutoCloseableAsync (common in flink-runtime: JobManager services, metric registries, HA services, blob server) when their async shutdown hook fails — e.g. a ZooKeeper connection error during HA service stop, or an RPC endpoint termination failure.

Common situations: Shutting down a mini-cluster or test harness while a dependent service (ZK, blob storage, RPC) is already broken; teardown during a failing test where the original failure surfaces only during close; double-closing a resource whose second close fails.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/d9041c2ff8a09e42. Report an issue: GitHub.