Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Q: will Mangum run lifespan multiple times? #208

Closed
dimaqq opened this issue Dec 6, 2021 · 1 comment
Closed

Q: will Mangum run lifespan multiple times? #208

dimaqq opened this issue Dec 6, 2021 · 1 comment

Comments

@dimaqq
Copy link

dimaqq commented Dec 6, 2021

I'm trying to run fastapi app with custom lifespan-aware middleware.
It works fine under uvicorn, but fails oddly under mangum.

The error is:

File "my-middleware-that-tries-to-honour-lifespan.py", line 98, in __call__
 await self.under.__aenter__()
File "/usr/local/lib/python3.10/contextlib.py", line 197, in __aenter__
 del self.args, self.kwds, self.func
AttributeError: args

(That's Py 3.10 error, the exception is a bit misleading: https://bugs.python.org/issue45996)

The cause is that my middleware accepts an instance of an asynccontextmanager, and it runs __aenter__ on lifespan.startup
and __aexit__ on lifespan.shutdown.

In the FastAPI/starlette/uvicorn combo, there's a case (maybe even an assumption) that startup and shutdown are ran only once. After that the entire app is thrown away.

However, it seems, as if mangum runs lifespan.startup multiple times.
Perhaps that's how it deals with lambda being suspended?

@jordaneremieff
Copy link
Owner

The startup and shutdown events are only expected to run once.

How are you running Mangum using 3.10? It currently only supports the latest Python version that AWS Lambda supports (3.9).

I’ll move this to discussions because it doesn’t seem like a bug specifically in Mangum at this point.

Repository owner locked and limited conversation to collaborators Dec 9, 2021
@jordaneremieff jordaneremieff converted this issue into discussion #211 Dec 9, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants