{"id":"829c80f84377dcac","repo":"apache/kafka","slug":"undefined-offset-with-no-reset-policy-for-partitio","errorCode":null,"errorMessage":"Undefined offset with no reset policy for partitions: ${partitionsWithNoOffsets}","messagePattern":"Undefined offset with no reset policy for partitions: (.+?)","errorType":"exception","errorClass":"NoOffsetForPartitionException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/internals/SubscriptionState.java","lineNumber":882,"sourceCode":"     *\n     * @param initPartitionsToInclude Initializing partitions to include in the reset. Assigned partitions that\n     *                                require a positions but are not included in this set won't be reset.\n     * @throws NoOffsetForPartitionException If there are partitions assigned that require a position but\n     *                                       there is no reset strategy configured.\n     */\n    public synchronized void resetInitializingPositions(Predicate<TopicPartition> initPartitionsToInclude) {\n        final Set<TopicPartition> partitionsWithNoOffsets = new HashSet<>();\n        assignment.forEach((tp, partitionState) -> {\n            if (partitionState.shouldInitialize() && initPartitionsToInclude.test(tp)) {\n                if (defaultResetStrategy == AutoOffsetResetStrategy.NONE)\n                    partitionsWithNoOffsets.add(tp);\n                else\n                    requestOffsetReset(tp);\n            }\n        });\n\n        if (!partitionsWithNoOffsets.isEmpty())\n            throw new NoOffsetForPartitionException(partitionsWithNoOffsets);\n    }\n\n    public synchronized void resetInitializingPositions() {\n        resetInitializingPositions(tp -> true);\n    }\n\n    public synchronized Set<TopicPartition> partitionsNeedingReset(long nowMs) {\n        return collectPartitions(state -> state.awaitingReset() && !state.awaitingRetryBackoff(nowMs));\n    }\n\n    public synchronized Map<TopicPartition, FetchPosition> partitionsNeedingValidation(long nowMs) {\n        Map<TopicPartition, FetchPosition> result = new HashMap<>();\n\n        assignment.forEach((tp, tps) -> {\n            if (tps.awaitingValidation() && !tps.awaitingRetryBackoff(nowMs) && tps.position != null) {\n                result.put(tp, tps.position);\n            }\n        });","sourceCodeStart":864,"sourceCodeEnd":900,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/SubscriptionState.java#L864-L900","documentation":"Thrown as NoOffsetForPartitionException by resetInitializingPositions when at least one assigned partition has no committed offset (no position) and the consumer's defaultResetStrategy is AutoOffsetResetPolicy.NONE (i.e. auto.offset.reset=none). The client refuses to silently pick earliest/latest and instead surfaces the gap so the application decides. This is the only path that raises NoOffsetForPartitionException; it fires during the position-initialization phase of poll().","triggerScenarios":"Configuring auto.offset.reset=none and then polling a group/topic where one or more partitions have no committed offset for this consumer group (new group, expired offsets after offset.retention, partition count change, or __consumer_offsets compaction/TTL). Also triggered after manually deleting a group's offsets via kafka-consumer-groups --delete-offsets.","commonSituations":"Production default of auto.offset.reset=none for safety, deployed against a brand-new topic; offsets expired because offsets.retention.minutes (default 7 days) lapsed during a consumer outage; partitions added by increasing topic partitions and the new partitions have no committed offset; broker-side __consumer_offsets topic was cleaned.","solutions":["Set auto.offset.reset to earliest or latest (whichever matches your data semantics) so the client can deterministically reset.","If 'none' is intentional for safety, catch NoOffsetForPartitionException, inspect partitionsWithNoOffsets, and explicitly consumer.seek() each partition to a chosen offset, then resume polling.","Use kafka-consumer-groups --reset-offsets to seed committed offsets before starting consumers if you need a one-time reset.","Raise offsets.retention.minutes on the broker if offsets are being aged out faster than consumer downtime."],"exampleFix":"// before\nprops.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, \"none\");\n\n// after\nprops.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, \"earliest\");\n// or handle explicitly:\ntry {\n    consumer.poll(Duration.ofMillis(500));\n} catch (NoOffsetForPartitionException e) {\n    for (TopicPartition tp : e.partitions()) consumer.seek(tp, 0L);\n}","handlingStrategy":"try-catch","validationCode":"// Avoid auto.offset.reset=none unless you explicitly want this failure.\nprops.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, \"earliest\"); // or \"latest\"\n// If you keep NONE, inspect committed offsets before the first poll loop:\nMap<TopicPartition, OffsetAndMetadata> committed = consumer.committed(consumer.assignment());\nSet<TopicPartition> missing = consumer.assignment().stream()\n    .filter(tp -> committed == null || committed.get(tp) == null)\n    .collect(Collectors.toSet());\nif (!missing.isEmpty()) {\n    consumer.seekToBeginning(missing); // explicit policy decision instead of throwing\n}","typeGuard":"import org.apache.kafka.clients.consumer.OffsetAndMetadata;\nimport org.apache.kafka.common.TopicPartition;\nimport java.util.Map;\n\n/** Partitions in 'assigned' with no committed offset (would trigger NoOffsetForPartitionException under reset=none). */\nstatic java.util.Set<TopicPartition> partitionsWithoutOffset(\n        Map<TopicPartition, OffsetAndMetadata> committed,\n        java.util.Set<TopicPartition> assigned) {\n    java.util.Set<TopicPartition> out = new java.util.HashSet<>();\n    for (TopicPartition tp : assigned) {\n        OffsetAndMetadata o = committed == null ? null : committed.get(tp);\n        if (o == null || o.offset() < 0) out.add(tp);\n    }\n    return out;\n}","tryCatchPattern":"try {\n    ConsumerRecords<K,V> records = consumer.poll(Duration.ofMillis(1000));\n} catch (org.apache.kafka.clients.consumer.NoOffsetForPartitionException e) {\n    // Apply an explicit reset instead of relying on the global policy.\n    consumer.seekToBeginning(e.partitions());   // or seekToEnd(e.partitions())\n    // optionally: commit the chosen offsets so the next restart is deterministic\n}","preventionTips":["Never set auto.offset.reset=none in production unless you wrap poll() in a NoOffsetForPartitionException handler.","Commit offsets before shutting down so the next start has a reset point.","On first deployment, bootstrap offsets via seekToBeginning/seekToEnd or a one-time loader.","Log committed-offset gaps during consumer startup to catch missing-offset state early."],"tags":["kafka","consumer","offset-reset","no-offset","configuration"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}