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

AssertionError after upgrading anyio to 4.7.0 #387

Closed
llybin opened this issue Dec 10, 2024 · 6 comments
Closed

AssertionError after upgrading anyio to 4.7.0 #387

llybin opened this issue Dec 10, 2024 · 6 comments

Comments

@llybin
Copy link

llybin commented Dec 10, 2024

AssertionError after upgrading anyio to 4.7.0

 Traceback (most recent call last):                                                                                                                                                                             │
│   File "/usr/local/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap                                                                                                                         │
│     self.run()                                                                                                                                                                                                 │
│   File "/usr/local/lib/python3.12/multiprocessing/process.py", line 108, in run                                                                                                                                │
│     self._target(*self._args, **self._kwargs)                                                                                                                                                                  │
│   File "/usr/local/lib/python3.12/site-packages/taskiq/cli/worker/run.py", line 153, in start_listen                                                                                                           │
│     loop.run_until_complete(receiver.listen(shutdown_event))                                                                                                                                                   │
│   File "/usr/local/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete                                                                                                                     │
│     return future.result()                                                                                                                                                                                     │
│            ^^^^^^^^^^^^^^^                                                                                                                                                                                     │
│   File "/usr/local/lib/python3.12/site-packages/taskiq/receiver/receiver.py", line 336, in listen                                                                                                              │
│     async with anyio.create_task_group() as gr:                                                                                                                                                                │
│                ^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                       │
│   File "/usr/local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 772, in __aenter__                                                                                                          │
│     self.cancel_scope.__enter__()                                                                                                                                                                              │
│   File "/usr/local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 425, in __enter__                                                                                                           │
│     task_state = _task_states[host_task]                                                                                                                                                                       │
│                  ~~~~~~~~~~~~^^^^^^^^^^^                                                                                                                                                                       │
│   File "/usr/local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 686, in __getitem__                                                                                                         │
│     assert isinstance(key, asyncio.Task)                                                                                                                                                                       │
│            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                       │
│ AssertionError    

https://github.com/agronholm/anyio/releases

Locking anyio=4.6.2 is solved the issue.

@s3rius
Copy link
Member

s3rius commented Dec 13, 2024

Could you please provide more details? I was able to upgrade to anyio 4.7.0 without any issues. Is the problem only affects a particular task, or any task? What broker are you using? It would also be very helpful if you could share a minimal reproducible example.

@llybin
Copy link
Author

llybin commented Dec 13, 2024

@s3rius thank you for the answer.

https://github.com/llybin/taskiq-anyio-4.7.0

(main) $ docker-compose up ppp-taskiq

here it reproducing, seems as taskiq configured some weird way in this project, but it worked with anyio=4.6.2

image

@s3rius
Copy link
Member

s3rius commented Dec 13, 2024

Thank you for such a great example. I will investigate.

@s3rius
Copy link
Member

s3rius commented Dec 13, 2024

@llybin, as a result of my investigation it's not an issue of taskiq. It's nest_asyncio which breaks anyio (which is direct dependency of taskiq). I have linked the issue where I posted a bit smaller MRE. Please follow any further discussion on a related issue in anyio repository.

Thanks you for providing the code.

@s3rius
Copy link
Member

s3rius commented Dec 13, 2024

Also, a small thing to add. I would generally recommend you to avoid using nest_asyncio, because of two things:

@llybin
Copy link
Author

llybin commented Dec 13, 2024

Thank you for your help. I will study and take your recommendations into account. All the best.

@llybin llybin closed this as completed Dec 13, 2024
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

2 participants