Not working for multiple workers by uvicorn
Describe the bug
Did anyone tried to use it for multiple workers >1 like 4 ?
uvicorn app.main:app --host 0.0.0.0 --port 8001 --workers 4
When multiple workers by uvicorn I think that different sub-processes are inside and session is not shared between workers (processes) then issue like detail
"AADSTS501481: The Code_Verifier does not match the code_challenge supplied in the authorization request. Trace ID:..."
To Reproduce Steps to reproduce the behavior:
- Run in docker by uvicorn app with workers 4
uvicorn app.main:app --host 0.0.0.0 --port 8001 --workers 4 - Click on login button
- Wait for result
- See error "AADSTS501481: The Code_Verifier does not match the code_challenge supplied in the authorization request. Trace ID:..."
Expected behavior It should not depend on which worker has this code in memory in one single session, but should share between processes.
Environment Settings
- OS: Linux / Docker (python:3.12)
- Python Version: 3.12
- Package Versions:
- msal: 1.32.3
- fastapi: 0.115.13
- fastapi_msal: 2.1.7
Additional context
@maveius - this is correct, but for this there should be a support for a file based / external session management like redis. Was on my roadmap but didn't got there. If required we can look into that together.
@dudil is there a good reason why it cannot be implemented stateless? if it can be we're happy to look into it with you :)
I would like to have this resolved as well. @dudil , @maveius , I propose to use diskcache (https://pypi.org/project/diskcache/) for this: performant and no dependency on an external server. Would that be a good option for you as well?
@dudil Let me know your preferred means of session storage, and I can look into this. Normally I'd go with redis, but if you have a preference, I'm happy to look at implementation.
@dudil Let me know your preferred means of session storage, and I can look into this. Normally I'd go with redis, but if you have a preference, I'm happy to look at implementation.
I am interested in this as well. But maybe it could have database interface as well?