Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions kafka/net/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, **configs):
if key in configs:
self.config[key] = configs[key]

self._running = False
self._closed = False
self._stop = False
self._selector = self.config['selector']()
Expand Down Expand Up @@ -264,6 +265,11 @@ def remove_writer(self, fileobj):
self.unregister_event(fileobj, selectors.EVENT_WRITE)

def poll(self, timeout_ms=None, future=None):
if self._current:
raise RuntimError('Recursive access to net.poll!')
elif self._running:
raise RuntimeError('Concurrent access to net.poll!')
self._running = True
start_at = time.monotonic()
inner_timeout = timeout_ms / 1000 if timeout_ms is not None else None
if future is not None and future.is_done:
Expand All @@ -276,6 +282,7 @@ def poll(self, timeout_ms=None, future=None):
inner_timeout = (timeout_ms / 1000) - (time.monotonic() - start_at)
if inner_timeout <= 0:
break
self._running = False

def _poll_once(self, timeout=None):
if self._ready:
Expand Down
2 changes: 2 additions & 0 deletions kafka/net/wakeup_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def _wakeup(self):
self._fut.success(None)

async def __call__(self, timeout_secs=None):
if self._fut is not None:
raise RuntimeError('Concurrent access to WakeupNotifier!')
self._fut = Future()
if timeout_secs is not None:
try:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_sasl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_client(request, sasl_kafka):
create_topics(sasl_kafka, [topic_name], num_partitions=1)

client = KafkaNetClient(**client_params(sasl_kafka, 'client'))
client._manager.run(client._manager.bootstrap)
client._manager.run(client._manager.bootstrap_async)
request = MetadataRequest(topics=None, version=1)
timeout_at = time.time() + 1
future = client.send(None, request)
Expand Down
Loading