SimpleConsumer: Socket connection gets negative buffersize
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.
What version of kafka-python? What broker version?
Kafka-python v1.3.1 and kafka v0.8.2.2
are you sharing a consumer across threads?
I have not been able to duplicate. Can you try upgrading to kafka-python 1.3.2?
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.
KafkaConsumer is not thread-safe and I do not recommend sharing between threads.