Skip to content

Commit 0f5d35f

Browse files
asdaraujojeffwidman
authored andcommitted
Check timeout type in KafkaClient constructor
If a future was passed as the only positional parameter it would be assigned to the "timeout_ms" parameter erroneously. This mistake would not raise any exception but would lead to odd behaviour later, what could make it extremely difficult to troubleshoot. Adding a type check ensures that an exception is raise earlier to notify the user about the problem.
1 parent 54d6410 commit 0f5d35f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kafka/client_async.py

+2
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@ def poll(self, timeout_ms=None, future=None):
545545
timeout_ms = 100
546546
elif timeout_ms is None:
547547
timeout_ms = self.config['request_timeout_ms']
548+
elif not isinstance(timeout_ms, (int, float)):
549+
raise RuntimeError('Invalid type for timeout: %s' % type(timeout_ms))
548550

549551
# Loop for futures, break after first loop if None
550552
responses = []

0 commit comments

Comments
 (0)