unit: Latest Docker Image Error Python failed to call 'asyncio.get_event_loop'
Upgrading our docker image from 1.28.0-python3.10 to 1.29.0-python3.11 results in the following log output:
2022/12/20 18:38:19 [info] 21#21 unit 1.29.0 started
2022/12/20 18:38:19 [info] 28#28 discovery started
2022/12/20 18:38:19 [notice] 28#28 module: python 3.11.1 "/usr/lib/unit/modules/python3.unit.so"
2022/12/20 18:38:19 [info] 24#24 controller started
2022/12/20 18:38:19 [notice] 24#24 process 28 exited with code 0
2022/12/20 18:38:19 [info] 33#33 router started
2022/12/20 18:38:19 [info] 33#33 OpenSSL 1.1.1n 15 Mar 2022, 101010ef
{
"certificates": {},
"config": {
"listeners": {},
"applications": {}
},
"status": {
"connections": {
"accepted": 0,
"active": 0,
"idle": 0,
"closed": 0
},
"requests": {
"total": 0
},
"applications": {}
}
}
/usr/local/bin/docker-entrypoint.sh: Looking for certificate bundles in /docker-entrypoint.d/...
/usr/local/bin/docker-entrypoint.sh: Looking for configuration snippets in /docker-entrypoint.d/...
/usr/local/bin/docker-entrypoint.sh: Applying configuration /docker-entrypoint.d/config.json
2022/12/20 18:38:19 [info] 44#44 "webapp" prototype started
2022/12/20 18:38:19 [info] 46#46 "webapp" application started
2022/12/20 18:38:19 [alert] 0#46 [unit] Python failed to call 'asyncio.get_event_loop'
2022/12/20 18:38:20 [notice] 44#44 app process 46 exited with code 1
2022/12/20 18:38:20 [warn] 33#33 failed to start application "webapp"
2022/12/20 18:38:20 [alert] 33#33 failed to apply new conf
2022/12/20 18:38:20 [notice] 24#24 process 44 exited with code 0
/usr/local/bin/docker-entrypoint.sh: Error: HTTP response status code is '500'
}error": "Failed to apply new configuration."
I’ve confirmed that this is a bug by replicating it with the simplest python application (copied from Unit docs):
async def application(scope, receive, send):
await send({"type": "http.response.start", "status": 200})
await send({"type": "http.response.body", "body": b"Hello, ASGI\n"})
Configuration is:
{
"listeners": {
"*:8080": {
"pass": "applications/webapp"
}
},
"applications": {
"webapp": {
"type": "python",
"path": "/www/",
"module": "nunittest.asgi",
"callable": "application"
}
}
}
There appears to be no path forward to using 1.29.0-python3.11 for an asgi application at all at this point, but perhaps I’m missing something?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 38 (20 by maintainers)
@tippexs Awesome, probably there would a bit of headache if not you 😉 Not a bad idea to clone repo in Dockerfile btw.
But to the point, I was able to build locally both
unit:1.30.0-python3.10usingmake build-python3.10 VERSION_python=3.10andunit:1.30.0-python3.11usingmake build-python3.11 VERSION_python=3.11just as you described it.Both are working alright with my setup where current official image
nginx/unit:1.29.0-python3.11fails.Steps to reproduce results if anybody is concerned (python 3.10/3.11 fastapi asgi app) can be found here https://github.com/rafsaf/nginx_unit_issue_815
If there is anything I could do, don’t hesitate, glad I could help.
Hi,
Using the sample fastapi app (ASGI) in your documentation https://unit.nginx.org/howto/fastapi/ After updating to 1.29.0 with python 3.11 , yielded same error in this issue
using same sample application with python 3.10 module compiled to work on unit 1.29.0 is working without any issue
Thanks @0x6f677548 👍
Sorry I dropped the ball on the comms on this one. It was indeed fixed with this fix and shipped with 1.29.1.
Updates! I was able to make it work with Unit 1.29 and Python 3.10.7. As soon as I am trying to use the latest Python 3.10 version which is 3.10.9 the app starts to crash on boot.
To build a container with Unit 1.29 and Python 3.10.7 issue
This will create a Docker image tagged as
unit:1.29.0-python3.10. Feel free to test your apps with this image. In the meantime we are looking into the issue with Python Versions > 3.10.7Here, perhaps this will help. This is the simplest recreation I can come up with. Create a Dockerfile with the following contents:
Then run it with this command
docker run --publish 8080:8080 --rm $(docker build -q .)which will build and run the dockerfile in the current directory.You’ll see that with 1.29.0 the server crashes, but if you uncomment the 1.28.0 image and comment out 1.29.0 that the server launches without issue.
@rafsaf Thanks for taking the time and effort to test this!
I will look at getting the patches reviewed and merged.
@lcrilly sure thing I can do it, hope I can find time today and try it on evening with an app that broke after image upgrade
@rafsaf we have a fix. Are you in a position to test it? https://github.com/ac000/unit/tree/asyncio
Sure, could help me out with an docker image or Dockerfile? I’d gladly will test it out.
[…]
Please, split that into a refactoring patch that adds the function, and then one that does the fix, to keep my sanity when reviewing 😃
I have just tested Unit 1.29 using Python 3.10 and I get the same error as with Python 3.11.
However even Unit 1.28.0 with Python3.10 shows me
So for me 1.28 AND 1.29 are failing regardless of the Python Versions 3.10 or 3.11.
Using the Images from the AWS ECR Registry the Unit 1.28 Python 3.10 Demo Application is working.
We are looking into it. I need to check if the custom build for our images is working as we expect.
@tippexs hi, thank you for working on that case!
Just like temporary workaround would be great to have docker image with unit 1.29.0 and python 3.10
Hi Team - I am working with the Dev Team on an analysis about the root cause. Will let you all know once we have something to share.
Atm. it looks like it is something new in the combination of Unit 1.29 and Python 3.11.1 as Python 3.10 on 1.29 works just fine.
Trying to reproduce this locally (current unit master, Python 3.11).
With the above config I get
With the following
$ cat /srv/unit/python/app/asgi.pyThe app seems to start, but not really…
From the log
And when trying to access it