Skip to content

Commit d3d3ad8

Browse files
authored
Send combined size and payload bytes to socket to avoid potentially split packets with TCP_NODELAY (#797)
1 parent b24a5c2 commit d3d3ad8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kafka/conn.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,17 @@ def _send(self, request, expect_response=True):
519519
client_id=self.config['client_id'])
520520
message = b''.join([header.encode(), request.encode()])
521521
size = Int32.encode(len(message))
522+
data = size + message
522523
try:
523524
# In the future we might manage an internal write buffer
524525
# and send bytes asynchronously. For now, just block
525526
# sending each request payload
526527
self._sock.setblocking(True)
527-
for data in (size, message):
528-
total_sent = 0
529-
while total_sent < len(data):
530-
sent_bytes = self._sock.send(data[total_sent:])
531-
total_sent += sent_bytes
532-
assert total_sent == len(data)
528+
total_sent = 0
529+
while total_sent < len(data):
530+
sent_bytes = self._sock.send(data[total_sent:])
531+
total_sent += sent_bytes
532+
assert total_sent == len(data)
533533
if self._sensors:
534534
self._sensors.bytes_sent.record(total_sent)
535535
self._sock.setblocking(False)

0 commit comments

Comments
 (0)