StickyPartitionAssignor.assign() loops forever when members subscribe to different topics
Los mantenedores suelen responder en 5 días
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 15/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- kafka, python
- Área
- distributed-systems
Línea de trabajo
The hang is in StickyAssignmentExecutor._perform_reassignments in kafka/coordinator/assignors/sticky/sticky_assignor.py, which calls _reassign_partition_to_consumer and PartitionMovements.get_partition_to_be_moved. Run the reproduction script from the issue under faulthandler to confirm it prints 'assignment completed' once fixed. The work is already under way in linked PR #3164, which includes a regression test, so review or extend that PR rather than starting a parallel fix.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
With StickyPartitionAssignor (and, since 3.0, CooperativeStickyAssignor, which uses the same executor), the group leader can hang forever in StickyAssignmentExecutor._perform_reassignments. Members subscribe to different topic sets. The leader never sends SyncGroup, so the whole group stalls.
Reproduced on master (3.1.0.dev), 3.0.11 and 2.3.2. The _reassign_partition_to_consumer code is identical on all three. For context, Apache Kafka's Java client (4.3.1) has the same logic and hangs on the same input.
Reproduction
Every member reports its owned partitions with generation -1, the default when on_assignment has not run yet.
import faulthandler
from kafka.coordinator.assignors.sticky.sticky_assignor import StickyPartitionAssignor
from kafka.protocol.consumer import JoinGroupResponse
from kafka.structs import TopicPartition
PARTITIONS = {'t5': 1, 't8': 12, 't10': 6, 't11': 11, 't12': 24, 't15': 1, 't17': 4}
SUBSCRIPTIONS = {
'c2-p3': ['t11'],
'c5-p2': ['t15', 't10'],
'c8-p0': ['t11', 't10', 't8'],
'c10-p3': ['t10', 't17'],
**{'c11-p%d' % i: ['t5', 't12', 't11'] for i in range(4)},
**{'c12-p%d' % i: ['t5', 't8', 't10'] for i in range(4)},
}
OWNED = {
'c5-p2': [('t10', 0), ('t10', 1)],
'c10-p3': [('t10', 4)],
'c11-p0': [('t11', 4), ('t11', 8)],
'c11-p1': [('t11', 5), ('t11', 9)],
'c11-p2': [('t11', 6), ('t11', 10)],
'c11-p3': [('t11', 3), ('t11', 7)],
'c12-p0': [('t10', 5), ('t8', 0), ('t8', 4), ('t8', 8)],
'c12-p1': [('t8', 1), ('t8', 5), ('t8', 9)],
'c12-p2': [('t10', 2), ('t8', 2), ('t8', 6), ('t8', 10)],
'c12-p3': [('t10', 3), ('t8', 3), ('t8', 7), ('t8', 11)],
}
class Cluster:
def topics(self):
return set(PARTITIONS)
def partitions_for_topic(self, topic):
return set(range(PARTITIONS[topic])) if topic in PARTITIONS else None
def member_metadata(member_id):
assignor = StickyPartitionAssignor()
assignor.member_assignment = [TopicPartition(t, p) for t, p in OWNED.get(member_id, [])]
return assignor.metadata(SUBSCRIPTIONS[member_id])
members = [
JoinGroupResponse.JoinGroupResponseMember(member_id=m, metadata=member_metadata(m))
for m in SUBSCRIPTIONS
]
faulthandler.dump_traceback_later(10, exit=True)
StickyPartitionAssignor().assign(Cluster(), members)
print('assignment completed')
Expected: assignment completed. Actual: the script never finishes. After 10 seconds, faulthandler shows a stack like this:
File ".../kafka/coordinator/assignors/sticky/sticky_assignor.py" in _is_balanced
File ".../kafka/coordinator/assignors/sticky/sticky_assignor.py" in _perform_reassignments
File ".../kafka/coordinator/assignors/sticky/sticky_assignor.py" in balance
File ".../kafka/coordinator/assignors/sticky/sticky_assignor.py" in assign
Root cause
_reassign_partition_to_consumer(partition, new_consumer) asks PartitionMovements.get_partition_to_be_moved(partition, consumer, new_consumer) which partition to move. consumer is the current, overloaded owner.
- Suppose
partitionalready moved from some consumer X toconsumerduring this rebalance. Thenget_partition_to_be_movedreplacesconsumerwith X and looks up the reverse pairnew_consumer -> X. - If a same-topic partition moved
new_consumer -> X, the method returns that partition as the substitute. X owns the substitute, notconsumer. _move_partition(substitute, new_consumer)moves it from X back tonew_consumer.consumerkeeps its load, so_is_balanced()stays false andmodifiedstays true. Thewhile Trueloop then repeats the same choice forever.
Proposed fix
If X owns the substitute, also move partition back to X. The substitute goes X -> new_consumer, then partition goes consumer -> X. Both movement records cancel, so no stickiness cycle remains. The net effect is that one partition leaves consumer, and new_consumer has at least 2 fewer partitions than consumer. The sum of squared assignment sizes therefore strictly decreases, and the loop terminates.
I have a PR with the fix and a regression test.
I used an AI coding assistant (Claude) to investigate this, write the fix, and draft this report.
- Lenguaje dominante
- Python
- Estrellas
- 5.9k
- Forks
- 1.5k
- Merge medio
- 6 d 5 h
- PR fusionados (30 d)
- 3
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dpkp/kafka-python
-
Transactional producer's sender loops on AttributeError after a fatal error (2.2 and 2.3 branches)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dpkp/kafka-python#3161 ·
Los mantenedores suelen responder en 5 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
dpkp/kafka-python#3122 · 13 comentarios ·
Los mantenedores suelen responder en 5 días
-
consumer
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
dpkp/kafka-python#3000 · 2 comentarios ·
Los mantenedores suelen responder en 5 días
-
documentation
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
dpkp/kafka-python#2715 ·
Los mantenedores suelen responder en 5 días
-
Expose option to enable `error_on_callbacks` in `KafkaProducer.send`Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertoproducer
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
dpkp/kafka-python#2366 ·
Los mantenedores suelen responder en 5 días
Todos los issues de dpkp/kafka-python
Issues similares
-
Project submission:Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
slavakurilyak/awesome-ai-agents#845 ·
Los mantenedores suelen responder en 1 día
-
tests: pin that the atomic writers in utils/paths.py stage the temporary file in the target's directoryPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodifficulty:2 enhancement good first issue
Dificultad 1/5 1-3 horas Aptitud para principiantes 92/100
MakazhanAlpamys/Soup#2178 ·
Los mantenedores suelen responder en 1 día
-
[BUG] dcg.waggr permutation p-values are folded twice, so near-zero scores get the smallest p-valuesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
scverse/rapids-singlecell#854 ·
Los mantenedores suelen responder en 1 día
-
Slang input: int8_t4_packed and uint8_t4_packed are copied into CrossGLPosiblemente ocupada @ninglinLiu la tomó hoy. Abiertoarea:frontend backend:slang bug direction:input
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
random_elements(unique=True) on an OrderedDict: ZeroDivisionError once only zero weights remain, AssertionError with use_weighting=FalsePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 13 días