Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several bugfixes and improvements #7

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

Gerrit-K
Copy link

@Gerrit-K Gerrit-K commented Nov 8, 2024

This is a collection of several changes, see list below and individual commit messages. If you want any of them not to be included (or pushed to a separate PR), please let me know!

  • Exit the application if there's an exception in one of the asyncio tasks
  • Remove gunicorn and start uvicorn directly
  • Fix a ValueError and a TypeError that got introduced in f283572

This fixes `ValueError: Incorrect label count`
This fixes `TypeError: unhashable type: 'list'`
This improves the cache utilization and speeds up development cycles
This app is mostly run in a container in k8s.
Running it with the process manager of gunicorn and a single uvicorn worker is not only unnecessary, but also makes signal handling slightly worse (e.g. SIGINT directly terminates uvicorn, but takes much longer in gunicorn).
It can also lead to a semi-healthy state, where the uvicorn worker is crashing, but the gunicorn process just spawns a new one, without surfacing the issue.

See also https://fastapi.tiangolo.com/deployment/docker/#replication-number-of-processes
When an exception occurs within an asyncio task, this doesn't interrupt the main flow.
This means that exceptions never surfaced and the webserver continued to serve metrics, although they might not have been updated anymore.

This wrapper catches any exception, logs it and then calls `sys.exit(1)`, so that the orchestrator (e.g. k8s) can recycle the container, allowing observability tools to notice that there is something wrong.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant