-
-
Notifications
You must be signed in to change notification settings - Fork 412
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
Opsdroid eventloop breaks if anyio.run() is called while there is an … #2037
base: main
Are you sure you want to change the base?
Conversation
…eventloop. According to AnyIO docs, anyio.run() must not have an event loop running in the current thread, which currently happens since loopless in the __init__ function is False. Identified this bug from debugging a slack connector, which pointed to this line as the culprit.
Shoot, yeah looks like that does cause problems for socket mode. I attempted to get test suite working utilizing anyio without touching any of actual project code but there was one test scenario in particular that I could not rectify without doing something about the presence of the event loop. If you can come up with a better solution until opsdroid can be converted completely to anyio that loopless option can probably be backed out completely.
I think this test will certainly fail if you run it yourself. |
so maybe this will do until anyio can be project wide? def sync_load(self):
"""Run the load modules method synchronously."""
# We are trying to run opsdroid without an event loop through anyio
# for testing purposes
if self.eventloop is None:
anyio.run(self.load)
else:
# We are running in the normal asyncio context
self.eventloop.run_until_complete(self.load()) @jacobtomlinson what do you think? Maybe a log warning/documentation that loopless is a gap measure and not recommended? I don't feel awesome about adding this stuff but I don't really have time to push for full anyio right now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have strong feelings here. It would be awesome to move towards anyio
everywhere, the async code here is very old so theres a lot of things that could be improved, task groups for a start would be very useful here.
Maybe we should just rever for now?
I would be fine reverting it but that still means that sync loading test will need to be addressed somehow or expected to fail until full anyio happens. Whatever smells the best to you works for me. I'm not sure just how much work full anyio is but maybe I'll have a poke around if you want to generate an issue for it. |
…eventloop. According to AnyIO docs, anyio.run() must not have an event loop running in the current thread, which currently happens since loopless in the init function is False. Identified this bug from debugging a slack connector, which pointed to this line as the culprit.
Description
Initially found error from trying to connect to Slack via websockets. Upon configuring Slack websockets as true, Opsdroid hangs. Upon further investigation, the webserver was also down, and figured out that the event loop was not working as intended. Inside the init function there is a loopless parameter that is defaulted to False, and so assume that opsdroid intends to loop and use the event loop. However anyio documentation states that "The current thread must not be already running an event loop." in order to use anyio.run() method. Changing the anyio code back to the original eventloop code fixes this issue and allows slack integration.
Did not revert any of the anyio changes made for the tests, just the instance found where it would affect runtime.
Status
READY
Type of change
How Has This Been Tested?
Tested with Slack Websockets configured as true in the configuration and with appropriate tokens.
Checklist: