alibaba/arthas · error · ApiException

consumer not found: {}

Error message

consumer not found: {}

What it means

Thrown by the HTTP API when a pull-results request references a consumerId that is not registered with the session's SharingResultDistributor. Each Arthas HTTP API session maintains a set of ResultConsumer instances keyed by consumerId; pulling results requires a previously created consumer. If the session has no distributor or the distributor has no consumer for that ID, this error fires.

Source

Thrown at core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java:502

    /**
     * Pull results from result queue
     *
     * @param apiRequest
     * @param session
     * @return
     */
    private ApiResponse processPullResultsRequest(ApiRequest apiRequest, Session session) throws ApiException {
        String consumerId = apiRequest.getConsumerId();
        if (StringUtils.isBlank(consumerId)) {
            throw new ApiException("'consumerId' is required");
        }
        ResultConsumer consumer = null;
        SharingResultDistributor resultDistributor = session.getResultDistributor();
        if (resultDistributor != null) {
            consumer = resultDistributor.getConsumer(consumerId);
        }
        if (consumer == null) {
            throw new ApiException("consumer not found: " + consumerId);
        }

        List<ResultModel> results = consumer.pollResults();
        Map<String, Object> body = new TreeMap<String, Object>();
        body.put("results", results);

        ApiResponse response = new ApiResponse();
        response.setState(ApiState.SUCCEEDED)
                .setSessionId(session.getSessionId())
                .setConsumerId(consumerId)
                .setBody(body);
        return response;
    }

    private boolean waitForJob(Job job, int timeout) {
        long startTime = System.currentTimeMillis();
        while (true) {
            switch (job.status()) {

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Ensure a consumer is created (PullResultsHandler / consumer registration) for this consumerId before issuing pull requests within the same session.
  2. Verify the consumerId in the request matches the one returned when the consumer was created and that the sessionId is still valid.
  3. If the session expired, re-create the session and re-register the consumer, then retry the pull.
  4. Check that session.getResultDistributor() is non-null — if the session was created without result distribution enabled, switch to a session type that supports it.

Example fix

// before: polling without registering a consumer
ApiRequest req = new ApiRequest();
req.setConsumerId("my-consumer");
pullResults(req); // throws 'consumer not found'

// after: register consumer first, then poll
String consumerId = session.getResultDistributor().createConsumer();
req.setConsumerId(consumerId);
pullResults(req);
Defensive patterns

Strategy: validation

Validate before calling

// Validate consumer exists before pulling
SharingResultDistributor distributor = session.getResultDistributor();
if (distributor == null || distributor.getConsumer(consumerId) == null) {
    // re-register consumer or return a friendly error to the client
    consumerId = distributor.createConsumer();
}
pullResults(consumerId);

Try / catch

try {
    pullResults(apiRequest);
} catch (ApiException e) {
    if (e.getMessage().contains("consumer not found")) {
        // re-create consumer and retry once
        String newConsumerId = session.getResultDistributor().createConsumer();
        apiRequest.setConsumerId(newConsumerId);
        pullResults(apiRequest);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling the /api/v1/pullResults (or equivalent) HTTP endpoint with a consumerId that was never created via a prior consumer-registration call, or using a consumerId from a different/expired session, or after the session's ResultDistributor was set to null.

Common situations: The client polled results before subscribing/creating a consumer; the session timed out and the distributor was torn down; a consumerId was typo'd or copy-pasted from another session; the HTTP API client retried after a session reconnect without re-registering its consumer.

Related errors


AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14). Data as JSON: /api/errors/8ef63084ee5753c6. Report an issue: GitHub.