[ https://issues.apache.org/jira/browse/KAFKA-17211?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17869311#comment-17869311 ]
yapeng commented on KAFKA-17211: -------------------------------- I noticed there is producer sender thread poll elements from Deque<ProducerBatch> and producer client may invoke RecordAccumulator.append. Both actions can make changes to head, tail to ArrayDeque. Although there is synchronized but it still has race conditions because head, tail are not defined as volatile in ArrayDeque. {code:java} public class ArrayDeque<E> extends AbstractCollection<E> implements Deque<E>, Cloneable, Serializable { /** * The array in which the elements of the deque are stored. * The capacity of the deque is the length of this array, which is * always a power of two. The array is never allowed to become * full, except transiently within an addX method where it is * resized (see doubleCapacity) immediately upon becoming full, * thus avoiding head and tail wrapping around to equal each * other. We also guarantee that all array cells not holding * deque elements are always null. */ transient Object[] elements; // non-private to simplify nested class access /** * The index of the element at the head of the deque (which is the * element that would be removed by remove() or pop()); or an * arbitrary number equal to tail if the deque is empty. */ transient int head; /** * The index at which the next element would be added to the tail * of the deque (via addLast(E), add(E), or push(E)). */ transient int tail; ......... ......... }{code} Is this possibly cause this bug? > kafka producer get stuck by Uncaught error in kafka producer I/O thread > ----------------------------------------------------------------------- > > Key: KAFKA-17211 > URL: https://issues.apache.org/jira/browse/KAFKA-17211 > Project: Kafka > Issue Type: Bug > Components: clients > Affects Versions: 2.8.2 > Reporter: yapeng > Priority: Major > > I have a kafka producer and it reported this error message forever. > {code:java} > [Producer clientId=xxxxxxxxxxxxxxx] Uncaught error in kafka producer I/O > thread: > java.util.NoSuchElementException: null > at java.util.ArrayDeque.getFirst(ArrayDeque.java:329) > at > org.apache.kafka.clients.producer.internals.RecordAccumulator.expiredBatches(RecordAccumulator.java:306) > at > org.apache.kafka.clients.producer.internals.Sender.sendProducerData(Sender.java:372) > at > org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:326) > at > org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:255) > at java.lang.Thread.run(Thread.java:750){code} > It seems wired that there has null values in Deque<ProducerBatch>. The > machine has been restarted to solve online issues so there is no heap dump. > Please help give some insights about this issue. -- This message was sent by Atlassian Jira (v8.20.10#820010)