Skip to content

Conversation

@tiangolo
Copy link
Member

@tiangolo tiangolo commented Feb 24, 2024

🐛 Fix unhandled growing memory for internal server errors, refactor dependencies with yield and except to require raising again as in regular Python.

This fixes a bug of growing unhandled memory/memory leak reported internally by @rushilsrivastava. 🤓

@tiangolo tiangolo marked this pull request as ready for review February 24, 2024 23:05
@tiangolo tiangolo merged commit bf771bd into master Feb 24, 2024
@tiangolo tiangolo deleted the raise-dependency branch February 24, 2024 23:06
@rushilsrivastava
Copy link

Thanks for the patch, sorry I didn't get a chance to open the discussion! 🙌

gisbdzhch pushed a commit to gisktzh/gb3-search_api that referenced this pull request Feb 29, 2024
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [fastapi](https://github.com/tiangolo/fastapi) | `==0.109.2` -> `==0.110.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/fastapi/0.110.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/fastapi/0.110.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/fastapi/0.109.2/0.110.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/fastapi/0.109.2/0.110.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>tiangolo/fastapi (fastapi)</summary>

### [`v0.110.0`](https://github.com/tiangolo/fastapi/releases/tag/0.110.0)

[Compare Source](fastapi/fastapi@0.109.2...0.110.0)

##### Breaking Changes

-   🐛 Fix unhandled growing memory for internal server errors, refactor dependencies with `yield` and `except` to require raising again as in regular Python. PR [#&#8203;11191](fastapi/fastapi#11191) by [@&#8203;tiangolo](https://github.com/tiangolo).
    -   This is a breaking change (and only slightly) if you used dependencies with `yield`, used `except` in those dependencies, and didn't raise again.
    -   This was reported internally by [@&#8203;rushilsrivastava](https://github.com/rushilsrivastava) as a memory leak when the server had unhandled exceptions that would produce internal server errors, the memory allocated before that point would not be released.
    -   Read the new docs: [Dependencies with `yield` and `except`](https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-with-yield/#dependencies-with-yield-and-except).

In short, if you had dependencies that looked like:

```Python
def my_dep():
    try:
        yield
    except SomeException:
        pass
```

Now you need to make sure you raise again after `except`, just as you would in regular Python:

```Python
def my_dep():
    try:
        yield
    except SomeException:
        raise
```

##### Docs

-   ✏️ Fix minor typos in `docs/ko/docs/`. PR [#&#8203;11126](fastapi/fastapi#11126) by [@&#8203;KaniKim](https://github.com/KaniKim).
-   ✏️ Fix minor typo in `fastapi/applications.py`. PR [#&#8203;11099](fastapi/fastapi#11099) by [@&#8203;JacobHayes](https://github.com/JacobHayes).

##### Translations

-   🌐 Add German translation for `docs/de/docs/reference/background.md`. PR [#&#8203;10820](fastapi/fastapi#10820) by [@&#8203;nilslindemann](https://github.com/nilslindemann).
-   🌐 Add German translation for `docs/de/docs/reference/templating.md`. PR [#&#8203;10842](fastapi/fastapi#10842) by [@&#820...
hsuanchi pushed a commit to hsuanchi/fastapi that referenced this pull request May 26, 2024
…ependencies with `yield` and `except` to require raising again as in regular Python (fastapi#11191)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants