Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock following timeout #42

Closed
NitzanBoden opened this issue May 24, 2023 · 0 comments
Closed

Deadlock following timeout #42

NitzanBoden opened this issue May 24, 2023 · 0 comments

Comments

@NitzanBoden
Copy link

NitzanBoden commented May 24, 2023

When attempting to send notifications with timeout, first timeout causes a deadlock to the sender making future request wait for a lock endlessly.

Example:

My code calls send_notifications with timeout:
response = await asyncio.wait_for(self.client.send_notification(request), timeout)

After multiple successful sends I got a timeout with:

Traceback (most recent call last):
  File \"/usr/local/lib/python3.10/site-packages/aioapns/client.py\", line 58, in send_notification
    response = await self.pool.send_notification(request)
  File \"/usr/local/lib/python3.10/site-packages/aioapns/connection.py\", line 387, in send_notification
    connection = await self.acquire()
  File \"/usr/local/lib/python3.10/site-packages/aioapns/connection.py\", line 358, in acquire
    connection = await self.create_connection()
  File \"/usr/local/lib/python3.10/site-packages/aioapns/connection.py\", line 501, in create_connection
    _, protocol = await self.loop.create_connection(
  File \"/usr/local/lib/python3.10/asyncio/base_events.py\", line 1089, in create_connection
    transport, protocol = await self._create_connection_transport(
  File \"/usr/local/lib/python3.10/asyncio/base_events.py\", line 1119, in _create_connection_transport
    await waiter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/usr/local/lib/python3.10/asyncio/tasks.py\", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

but since it exits without releasing the lock it acquires - all future requests gets stuck waiting for the same lock:

Traceback (most recent call last):
  File \"/usr/local/lib/python3.10/site-packages/aioapns/client.py\", line 58, in send_notification
    response = await self.pool.send_notification(request)
  File \"/usr/local/lib/python3.10/site-packages/aioapns/connection.py\", line 387, in send_notification
    connection = await self.acquire()
  File \"/usr/local/lib/python3.10/site-packages/aioapns/connection.py\", line 351, in acquire
    await self._lock.acquire()
  File \"/usr/local/lib/python3.10/asyncio/locks.py\", line 114, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/usr/local/lib/python3.10/asyncio/tasks.py\", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

Was there a reason you chose to not use a context manager with this lock? If not is it possible to change it to use one to avoid this situation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant