@@ -122,6 +122,9 @@ class BrokerConnection(object):
122122 max_in_flight_requests_per_connection (int): Requests are pipelined
123123 to kafka brokers up to this number of maximum requests per
124124 broker connection. Default: 5.
125+ receive_message_max_bytes (int): Maximum allowed network frame size.
126+ Used to avoid OOM when decoding malformed network message header.
127+ Default: 1000000.
125128 receive_buffer_bytes (int): The size of the TCP receive buffer
126129 (SO_RCVBUF) to use when reading data. Default: None (relies on
127130 system defaults). Java client defaults to 32768.
@@ -202,6 +205,7 @@ class BrokerConnection(object):
202205 'reconnect_backoff_ms' : 50 ,
203206 'reconnect_backoff_max_ms' : 30000 ,
204207 'max_in_flight_requests_per_connection' : 5 ,
208+ 'receive_message_max_bytes' : 1000000 ,
205209 'receive_buffer_bytes' : None ,
206210 'send_buffer_bytes' : None ,
207211 'socket_options' : [(socket .IPPROTO_TCP , socket .TCP_NODELAY , 1 )],
@@ -292,7 +296,8 @@ def __init__(self, host, port, afi, **configs):
292296
293297 self ._protocol = KafkaProtocol (
294298 client_id = self .config ['client_id' ],
295- api_version = self .config ['api_version' ])
299+ api_version = self .config ['api_version' ],
300+ max_frame_size = self .config ['receive_message_max_bytes' ])
296301 self .state = ConnectionStates .DISCONNECTED
297302 self ._reset_reconnect_backoff ()
298303 self ._sock = None
0 commit comments