Skip to content

Commit 61058bb

Browse files
committed
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 f8dd6c8 commit 61058bb

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kafka/client_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ def poll(self, timeout_ms=None, future=None, delayed_tasks=True):
526526
timeout_ms = 100
527527
elif timeout_ms is None:
528528
timeout_ms = self.config['request_timeout_ms']
529+
elif not isinstance(timeout_ms, int) and not isinstance(timeout_ms, float):
530+
raise RuntimeError('Invalid type for timeout: %s' % (type(timeout_ms),))
529531

530532
responses = []
531533

0 commit comments

Comments
 (0)