apache/rocketmq · error · MQClientException

SYSTEM_ERROR

SYSTEM_ERROR

Error message

Found unexpected result {result}

What it means

Thrown by RebalancePushImpl.computePullFromWhere as a final invariant check: after the ConsumeFromWhere switch, the computed initial offset is still negative. Since every branch should yield >= 0 (stored offset, 0, maxOffset, or searchOffset result), a negative result means an unhandled combination — for example searchOffset returning -1 because no message existed at/after the consume timestamp. Code SYSTEM_ERROR marks it as an unexpected internal outcome rather than a config problem.

Source

Thrown at client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java:244

                            result = this.mQClientFactory.getMQAdminImpl().searchOffset(mq, timestamp);
                        } catch (MQClientException e) {
                            log.warn("Compute consume offset from last offset exception, mq={}, exception={}", mq, e);
                            throw e;
                        }
                    }
                } else {
                    throw new MQClientException(ResponseCode.QUERY_NOT_FOUND, "Failed to query offset from offset " +
                            "store");
                }
                break;
            }

            default:
                break;
        }

        if (result < 0) {
            throw new MQClientException(ResponseCode.SYSTEM_ERROR, "Found unexpected result " + result);
        }

        return result;
    }

    @Override
    public int getConsumeInitMode() {
        final ConsumeFromWhere consumeFromWhere = this.defaultMQPushConsumerImpl.getDefaultMQPushConsumer().getConsumeFromWhere();
        if (ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET == consumeFromWhere) {
            return ConsumeInitMode.MIN;
        } else {
            return ConsumeInitMode.MAX;
        }
    }

    @Override
    public void dispatchPullRequest(final List<PullRequest> pullRequestList, final long delay) {
        for (PullRequest pullRequest : pullRequestList) {

View on GitHub (pinned to 293f588571)

Solutions

  1. Set consumeTimestamp to a value within the topic's retention window (after the earliest message still on the broker)
  2. If the queue may legitimately be empty or lack messages at that timestamp, prefer CONSUME_FROM_LAST_OFFSET or handle SYSTEM_ERROR at start with a retry after messages arrive
  3. Verify the timestamp format is yyyyMMddHHmmss and represents a real point in time on that queue

Example fix

// before
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_TIMESTAMP);
consumer.setConsumeTimestamp("20200101000000"); // older than retained messages -> searchOffset -1
// after
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET); // or
consumer.setConsumeTimestamp("20240601000000"); // inside retention window
Defensive patterns

Strategy: validation

Validate before calling

// before start: assert timestamp lies within the topic's retention window
long ts = UtilAll.parseDate(consumeTimestamp, UtilAll.YYYYMMDDHHMMSS).getTime();
long min = admin earliestMsgTime(topic), max = System.currentTimeMillis();
if (ts < min) throw new IllegalArgumentException("consumeTimestamp older than earliest retained message; use LAST_OFFSET or a later time");

Try / catch

catch (MQClientException e) { if (e.getResponseCode() == ResponseCode.SYSTEM_ERROR && e.getMessage().contains("unexpected result")) { consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET); rebuildAndStart(); } else throw e; }

Prevention

When it happens

Trigger: CONSUME_FROM_TIMESTAMP with a consumeTimestamp earlier than the earliest message on the queue (searchOffset returns -1), or future edge combinations (unknown ConsumeFromWhere falling through the switch with result still -1 initialization value).

Common situations: consumeTimestamp set to a date before the topic's earliest retained message (expired by retention); consumeTimestamp in the far future; timestamps formatted wrongly so parsing yields epoch 0 and the queue has no matching message; newly-created queue with no messages when using TIMESTAMP mode.

Related errors


AI-assisted analysis of apache/rocketmq@293f588571 (2026-08-14). Data as JSON: /api/errors/cfba0c58e6ee2cdc. Report an issue: GitHub.