unit: strange error when serving app from starlette
I get 503 error when running nginx+unit serving the example starlette app (https://unit.nginx.org/howto/starlette/). The complete log for unit is:
2022/01/26 00:37:51 [info] 33216#139127 discovery started
2022/01/26 00:37:51 [notice] 33216#139127 module: python 3.10.2 "/home/shared/Builds/unit-1.26.1/modules/python3.10.unit.so"
2022/01/26 00:37:51 [info] 36261#518939 controller started
2022/01/26 00:37:51 [notice] 36261#518939 process 33216 exited with code 0
2022/01/26 00:37:51 [info] 58715#394694 router started
2022/01/26 00:37:51 [info] 58715#394694 OpenSSL 1.1.1l 24 Aug 2021, 101010cf
2022/01/26 00:37:51 [info] 93430#495270 "myapp" prototype started
2022/01/26 00:37:51 [info] 32427#513572 "myapp" application started
2022/01/26 00:38:30 [alert] 32427#513572 [unit] #8: Python failed to create 'client' pair
2022/01/26 00:38:30 [alert] 32427#513572 [unit] Python failed to call 'loop.call_soon'
Traceback (most recent call last):
File "/home/shared/Builds/Python-3.10.2/lib/python3.10/asyncio/base_events.py", line 745, in call_soon
self._check_closed()
ValueError: invalid literal for int() with base 10: ''
I am using Python3.10.2. I have nginx pointing to unit via unix socket. The error is very strange I am not able to figure what could be wrong. Happy to provide any more information as needed.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (11 by maintainers)
Commits related to this issue
- Python: supporting UNIX sockets. This closes #635 issue on GitHub. — committed to nginx/unit by alejandro-colomar 2 years ago
I think this is failing even before the port thing. I remember seeing this error in the log too:
https://github.com/nginx/unit/blob/aeed86c6829c62359e79f239b849766efb8857a7/src/python/nxt_python_asgi.c#L666
Line 666, BTW xD
We’ll check later.
Okay, we have a fix. There’s something I don’t know, and that’s if I need to
Py_INCREF(Py_None)or not. I’ll open a PR soon, so you can check it, but the fix is already in my test branch, so you can have a look at it: https://github.com/alejandro-colomar/unit/tree/sock-test.I changed your repository a bit to serve a static website instead of a python/falcon app, and it works. So we need to fix the code for python ASGI, as @mar0x said.
I traced the 503 error source to
src/nxt_router.c:4508:https://github.com/alejandro-colomar/unit/blob/91ba4f138cdb7581cfbd9a426b8a180e2173e6b0/src/nxt_router.c#L4508
@VBart, Good morning!
Unfortunately, the solution you suggested, with the implementation of the PR extension https://github.com/nginx/unit/pull/655 by @alejandro-colomar, only solves the
client_ippart of the problem usingX-Forwarded-For.I have created a repository with the ability to quickly reproduce this problem in just one command: https://github.com/echolimazulu/unit-asgi-503
@alejandro-colomar, Good morning!
This is what you requested earlier in issue https://github.com/nginx/unit/issues/642
Please pay attention to the possibility of finding a solution to this problem based on the data I provided.
Thank you very much for your attention to this issue!