kafka-python icon indicating copy to clipboard operation
kafka-python copied to clipboard

SimpleConsumer: Socket connection gets negative buffersize

Open khangnguyen opened this issue 9 years ago • 6 comments

I am using SimpleConsumer (acknowledged it is deprecated) with auto_commit. My program tends to crash with varying frequency (days to hours) with the following error.

Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/site-packages/kafka/util.py", line 135, in _timer
    self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python2.7/site-packages/kafka/consumer/base.py", line 164, in commit
    self.client.send_offset_commit_request(self.group, reqs)
  File "/usr/lib/python2.7/site-packages/kafka/client.py", line 685, in send_offset_commit_request
    resps = self._send_broker_aware_request(payloads, encoder, decoder)
  File "/usr/lib/python2.7/site-packages/kafka/client.py", line 286, in _send_broker_aware_request
    conn.recv()
  File "/usr/lib/python2.7/site-packages/kafka/conn.py", line 586, in recv
    return self._recv()
  File "/usr/lib/python2.7/site-packages/kafka/conn.py", line 593, in _recv
    data = self._sock.recv(bytes_to_read)
ValueError: negative buffersize in recv

I don't know what might have caused it, nor is there a way to catch this error in application code and handle it properly without crashing.

khangnguyen avatar Feb 18 '17 15:02 khangnguyen

What version of kafka-python? What broker version?

jeffwidman avatar Feb 18 '17 17:02 jeffwidman

Kafka-python v1.3.1 and kafka v0.8.2.2

khangnguyen avatar Feb 18 '17 17:02 khangnguyen

are you sharing a consumer across threads?

dpkp avatar Mar 02 '17 19:03 dpkp

I have not been able to duplicate. Can you try upgrading to kafka-python 1.3.2?

dpkp avatar Mar 07 '17 22:03 dpkp

It is indeed hard to replicate. The consumer is shared between threads. I have picked up clues that this isn't a good idea. Would upgrading to 1.3.2 improve this? Also, would putting a consumer in each thread (they won't pull messages at the same time, consumer only pulls message when a thread started, which happens every 5s) help? Thanks.

khangnguyen avatar Mar 08 '17 08:03 khangnguyen

KafkaConsumer is not thread-safe and I do not recommend sharing between threads.

dpkp avatar Mar 09 '17 19:03 dpkp