Kafka Exception TaskAssignmentException
org.apache.kafka.streams.errors.TaskAssignmentException
Non-retriable
Streams
Indicates a run time error incurred while trying to assign StreamTask stream tasks to StreamThread threads.
Common Causes
- The StreamsPartitionAssignor's onAssignment consistency check failed: the number of assigned partitions did not equal the number of active task ids in the decoded AssignmentInfo, signaling a partition-to-task mapping inconsistency.
- A custom PartitionGrouper / TaskAssignor (pre-KIP-924) produced an invalid mapping — e.g. a partition with no corresponding task id, or a task missing one of its input partitions.
- Version/subscription metadata skew across instances during a rolling upgrade, so the leader computed an assignment some members could not decode/apply consistently.
- Corrupted or stale AssignmentInfo (incompatible assignor version, named-topology edge cases) causing the assignor to refuse the assignment rather than encode a partial task.
Solutions
- Don't ship a custom assignor unless required; rely on the built-in HighAvailabilityTaskAssignor. If you must customize, use the KIP-924 TaskAssignor SPI and ensure every assigned partition maps to exactly one task.
- Keep all application instances on the same Kafka Streams version and the same topology so the assignor's subscription/assignment metadata is consistent; finish rolling upgrades promptly.
- Reset the application (kafka-streams-application-reset.sh) and restart if a corrupted topology/assignment state is suspected, so internal topics and assignment metadata are regenerated cleanly.
- Capture the full message ('Number of assigned partitions ... is not equal to the number of active taskIds ...') and the topology/version; advanced users on KIP-924 can swallow a TaskAssignmentException and schedule a followup rebalance via the followupRebalanceDeadline.
Example Stack Trace
org.apache.kafka.streams.errors.TaskAssignmentException: Number of assigned partitions 6 is not equal to the number of active taskIds 5, assignmentInfo=AssignmentInfo{version=10, ...}
at org.apache.kafka.streams.processor.internals.StreamsPartitionAssignor.onAssignment(StreamsPartitionAssignor.java:1402)
at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.invokeOnAssignment(ConsumerCoordinator.java:312)
at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.onJoinComplete(ConsumerCoordinator.java:415)Diagnostic Commands
kafka-streams-application-reset.sh --application-id my-app --bootstrap-server localhost:9092 # regenerate internal/assignment topics if the mapping is corrupted
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-app --members --verbose # inspect per-member partition assignmentRelated
Related Streams exceptions: BrokerNotFoundException · InternalTopicsAlreadySetupException · InvalidStateStoreException · InvalidStateStorePartitionException · LockException · MisconfiguredInternalTopicException · MissingInternalTopicsException · MissingSourceTopicException
Hitting
TaskAssignmentException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.