apache/beam · error · IllegalStateException

response.get().getError()

Error message

response.get().getError()

What it means

OrderedListUserState.asyncClose throws this IllegalStateException when the beamFnStateClient response for a pending clear (range-clear) request carries a non-empty error field. It surfaces an error reported by the runner/state service when flushing buffered range removals at close time, and includes the runner's error message verbatim.

Solutions

  1. Read the IllegalStateException message for the runner's underlying state error
  2. Verify the instruction ID is still valid (bundle not already finished) when closing state
  3. Check runner/logs for state backend failures (e.g. state service unavailable)
  4. Ensure clearRange ranges are valid (start <= end, within list bounds) before buffering removes

Example fix

// before: swallowing range errors until close
state.clearRange(start, end);
// after: validate range before issuing
if (start.compareTo(end) > 0) throw new IllegalArgumentException("start > end");
state.clearRange(start, end);
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate ranges before clearing
if (start.getMillis() > end.getMillis()) {
  throw new IllegalArgumentException("clearRange start after end");
}

Try / catch

try (OrderedListUserState state = ...) {
  ...
} catch (IllegalStateException e) {
  logger.error("orderedList clear failed: {}", e.getMessage());
  throw e;
}

Prevention

When it happens

Trigger: Calling asyncClose (e.g. via try-with-resources or at bundle finish) while pendingRemoves exist and the StateRequest handling returns a response whose getError() is non-empty.

Common situations: Runner-side state backend failures; invalid range endpoints sent for clearRange; connection/instruction ID problems with the state service; timeouts on the state client future also surface here (ExecutionException from response.get()).

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/a5121d4a6cb3dcdc. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/OrderedListUserState.java:300

  }

  public void asyncClose() throws Exception {
    isClosed = true;

    if (!pendingRemoves.isEmpty()) {
      for (Range<Instant> r : pendingRemoves.asRanges()) {
        StateRequest.Builder stateRequest = this.requestTemplate.toBuilder();
        stateRequest.setClear(StateClearRequest.newBuilder().build());
        stateRequest
            .getStateKeyBuilder()
            .getOrderedListUserStateBuilder()
            .getRangeBuilder()
            .setStart(r.lowerEndpoint().getMillis())
            .setEnd(r.upperEndpoint().getMillis());

        CompletableFuture<StateResponse> response = beamFnStateClient.handle(stateRequest);
        if (!response.get().getError().isEmpty()) {
          throw new IllegalStateException(response.get().getError());
        }
      }
      pendingRemoves.clear();
    }

    if (!pendingAdds.isEmpty()) {
      ByteStringOutputStream outStream = new ByteStringOutputStream();

      for (Entry<Instant, Collection<T>> entry : pendingAdds.entrySet()) {
        for (T v : entry.getValue()) {
          TimestampedValue<T> tv = TimestampedValue.of(v, entry.getKey());
          try {
            timestampedValueCoder.encode(tv, outStream);
          } catch (IOException ex) {
            throw new RuntimeException(ex);
          }
        }
      }

View on GitHub (pinned to 12126d8942)