Skip to content

Commit 4ffd4e9

Browse files
committed
Always truncate deallocated produce message buffers
1 parent f989852 commit 4ffd4e9

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

kafka/producer/buffer.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,12 @@ def deallocate(self, buf):
191191
buffer_ (io.BytesIO): The buffer to return
192192
"""
193193
with self._lock:
194-
capacity = buf.seek(0, 2)
195-
196-
# free extra memory if needed
197-
if capacity > self._poolable_size:
198-
# BytesIO (cpython) only frees memory if 2x reduction or more
199-
trunc_to = int(min(capacity / 2, self._poolable_size))
200-
buf.truncate(trunc_to)
201-
202-
buf.seek(0)
203-
#buf.write(bytearray(12))
204-
#buf.seek(0)
194+
# BytesIO.truncate here makes the pool somewhat pointless
195+
# but we stick with the BufferPool API until migrating to
196+
# bytesarray / memoryview. The buffer we return must not
197+
# expose any prior data on read().
198+
buf.truncate(0)
205199
self._free.append(buf)
206-
207200
if self._waiters:
208201
self._waiters[0].notify()
209202

0 commit comments

Comments
 (0)