question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uvirorn.workers.UvicornWorker fails with certain ASGI middleware

See original GitHub issue

Description

Certain middleware is fails, either when launcing Uvicornworker, or when calling the ASGI handler. A concrete case is the SentryAsgiMiddleware. See https://github.com/getsentry/sentry-python/issues/947 for info. Not sure if the problem is in Uvicorn or Sentry.

To reproduce

Install the Sentry lib in a ASGI application, run with gunicorn/uviworker

from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
app = SentryAsgiMiddleware(app)

and

gunicorn api:app -w 1 -k uvicorn.workers.UvicornWorker

Expected behavior

Application launches and runs

Actual behavior

As set up above, the following error is produced when launcing gunicorn:

File "/usr/lib/python3.7/inspect.py", line 2208, in _signature_from_callable
    raise TypeError('{!r} is not a callable object'.format(obj))

If I forcefully expose either a asgi2 or asgi3 interface from the middleware, using either the _run_asgi2() or _run_asgi3() methods on the middleware object, the servers starts up, but then fails when handling a request, with e.g.:

TypeError: _run_asgi3() missing 2 required positional arguments: 'receive' and 'send'

Apparently, the introspection of the callable fails to recognize method objects.

Additional context

Using the uvicorn webserver it is possible to specify asgi2/3 interface using a commandline argument, and thus override the detection mechanism, which seems to be failing on this particular middleware. Using the Uvicorn worker this appears to be not possible.

again, see issue here. See https://github.com/getsentry/sentry-python/issues/947 for info.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
kristjanvalurcommented, Dec 21, 2020

Hm, being an old school Python guy, I probably would have opted for just calling the object, without an argument, and if that worked, assume that it was a factory. Otherwise, handle the exception and assume it was an app instance. In my experience type inspection only ever caused grief.

1reaction
florimondmancacommented, Dec 19, 2020

To be clear AFAICT the bug here is not related to determining ASGI 2 vs ASGI 3, but related to “app instances” vs “app factories”. The latter case was introduced recently via a --factory flag, and the code at fault was meant to try and detect when a factory is passed without the flag (so we don’t just crash with an odd “app expected 0 arguments but got 3” error message).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deployment - Uvicorn
As a general rule, you probably want to: Run uvicorn --reload from the command line for local development. Run gunicorn -k uvicorn.workers.UvicornWorker for ......
Read more >
Uvicorn async workers are still working synchronously
I have created an async view, setup asgi configuration, and run gunicorn with a Uvicorn worker. When swarming this server with 10 users ......
Read more >
Error in ASGI app - Agents - New Relic Explorers Hub
Hi. I get the error [2019-12-12 11:30:16 +0000] [11] [ERROR] Exception in ASGI application Traceback (most recent call last): File ...
Read more >
Server Workers - Gunicorn with Uvicorn - FastAPI
And then the Gunicorn-compatible Uvicorn worker class would be in charge of converting the data sent by Gunicorn to the ASGI standard for...
Read more >
tiangolo/fastapi - Gitter
Note: I don't see any issue/second hit when I don't have any middleware. Thanks. ... I ran the test server via Gunicorn's uvicorn...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found