apache/flink · error · UnsupportedOperationException

Do not support external resource in current environment

Error message

Do not support external resource in current environment

What it means

RuntimeUDFContext is a standalone RuntimeContext implementation used by the CollectionExecutor (the local in-memory/DataSet batch executor). It does not wire up an ExternalResourceInfoProvider, so its getExternalResourceInfos(resourceName) unconditionally throws UnsupportedOperationException. External resources (e.g. GPU device info) are only resolvable by the real distributed/streaming runtime contexts (StreamingRuntimeContext, DistributedRuntimeUDFContext), which delegate to an ExternalResourceInfoProvider populated from the TaskManager's configured external resources.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/functions/util/RuntimeUDFContext.java:146

        Object o = this.initializedBroadcastVars.get(name);
        if (o != null) {
            return (C) o;
        } else {
            List<T> uninitialized = (List<T>) this.uninitializedBroadcastVars.remove(name);
            if (uninitialized != null) {
                C result = initializer.initializeBroadcastVariable(uninitialized);
                this.initializedBroadcastVars.put(name, result);
                return result;
            } else {
                throw new IllegalArgumentException(
                        "The broadcast variable with name '" + name + "' has not been set.");
            }
        }
    }

    @Override
    public Set<ExternalResourceInfo> getExternalResourceInfos(String resourceName) {
        throw new UnsupportedOperationException(
                "Do not support external resource in current environment");
    }

    // --------------------------------------------------------------------------------------------

    public void setBroadcastVariable(String name, List<?> value) {
        this.uninitializedBroadcastVars.put(name, value);
        this.initializedBroadcastVars.remove(name);
    }

    public void clearBroadcastVariable(String name) {
        this.uninitializedBroadcastVars.remove(name);
        this.initializedBroadcastVars.remove(name);
    }

    public void clearAllBroadcastVariables() {
        this.uninitializedBroadcastVars.clear();
        this.initializedBroadcastVars.clear();

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Run the job on a real streaming execution environment (StreamExecutionEnvironment) or a real cluster so the RuntimeContext is a StreamingRuntimeContext backed by a configured ExternalResourceInfoProvider.
  2. If this is a unit test, construct StreamingRuntimeContext (or mock RuntimeContext) with an ExternalResourceInfoProvider instead of RuntimeUDFContext.
  3. Configure the external resource on the TaskManager (external-resources entry in flink-conf.yaml) so the provider actually returns resource info.
  4. Guard the call by checking the execution mode / runtime context type before invoking getExternalResourceInfos.

Example fix

// before (fails under CollectionExecutor)
Set<ExternalResourceInfo> info = getRuntimeContext().getExternalResourceInfos(resourceName);

// after: only query when the real runtime supports it
RuntimeContext ctx = getRuntimeContext();
if (ctx instanceof StreamingRuntimeContext) {
    Set<ExternalResourceInfo> info = ctx.getExternalResourceInfos(resourceName);
    // use GPU info
} else {
    // fallback or fail-fast with a clear message
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate runtime context type supports external resources before calling.
RuntimeContext ctx = getRuntimeContext();
boolean supportsExt = (ctx instanceof StreamingRuntimeContext)
        || (ctx instanceof DistributedRuntimeUDFContext);
if (!supportsExt) {
    // skip accelerator code path or fail with a clear message
}

Prevention

When it happens

Trigger: Calling getRuntimeContext().getExternalResourceInfos(name) from inside a function (e.g. a RichMapFunction or the GPU streaming example MatrixVectorMul) while the job is executed via CollectionEnvironment / LocalEnvironment batch execution, or via ExecutionEnvironment.createCollectionsEnvironment(). Also hit in unit tests that construct a RuntimeUDFContext directly and exercise a function that queries external resources.

Common situations: Running GPU/accelerator-using jobs locally or in a test with ExecutionEnvironment that resolves to CollectionExecutor; porting a streaming GPU function to the legacy DataSet API; writing a unit test that manually builds RuntimeUDFContext instead of StreamingRuntimeContext.

Related errors


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