-
Notifications
You must be signed in to change notification settings - Fork 426
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
Memory leak in aiohttp integration since v2.2.0 #8108
Comments
Thank you for reporting this issue, @agronholm. We'll look into it. |
Same problem. Huge impact : dd-trace last version is unusable for us. |
Seems likely that the culprit PR is this one: This introduces basic tracing of streaming responses that stay open long after the on_prepare signal has been sent. since it's the only aiohttp integration change in 2.2.0. Waiting to end spans sounds like it could easily end up causing a memory leak, perhaps our callback is never getting called, or the request_span isn't in the request by the time we call the callback, and then we just return. I'll test this and will update here. |
Then why is it that the trivial app I provided also exhibits this? |
I just noticed this issue. This makes newer versions of From my investigation I would say that: |
This issue has been automatically closed after a period of inactivity. If it's a |
Has this been tackled at all? this got auto closed. |
… a done callback on streaming responses (DataDog#8108)
Hello - I've submitted #11518, which should remove the strong reference to the response object in the task callback, as well as fix the type check so we only add the callback when we have an actual stream response. |
…g responses(DataDog#8108) Without this change, the request and response objects are not freed from memory until the asyncio Task is freed, which can create a memory leak. This change leverages a contextvar to accomplish the same result as the previous version, while ensuring any memory is freed once the current async context is exited.
…g responses(DataDog#8108) Without this change, the request and response objects are not freed from memory until the asyncio Task is freed, which can create a memory leak. This change leverages a contextvar to accomplish the same result as the previous version, while ensuring any memory is freed once the current async context is exited.
…g responses(DataDog#8108) Without this change, the request and response objects are not freed from memory until the asyncio Task is freed, which can create a memory leak. This change leverages a contextvar to accomplish the same result as the previous version, while ensuring any memory is freed once the current async context is exited.
…g responses(DataDog#8108) Without this change, the request and response objects are not freed from memory until the asyncio Task is freed, which can create a memory leak. This change leverages a contextvar to accomplish the same result as the previous version, while ensuring any memory is freed once the current async context is exited.
Hello! I'm reopening this issue given #11518 since I'm trying to see how we can test the change. Regarding #8108 (comment)
@agronholm, if this is still an issue, can you share some details about:
And for others in this thread running into this, can you provide examples of the sample application (or code snippets), along with the questions above so we can understand the conditions in which this memory leak happens to test for it? If there are private details that are specific to your application that you don't want to share on Github, please open a support ticket via https://docs.datadoghq.com/help/ referencing this ticket and we'll investigate it in parallel. Thank you very much in advance! |
Help us replicate the issue! We took the sample code in this issue and tried to replicate the behavior. The below pictures are from DD_VERSION=good and DD_VERSION=bad. Good Version: 2.1.9 of the We used apache load generator to send a bunch of requests, and see no uptick in memory. |
Hey folks - Apologies for being a bit awol - it's launch season at work and I've been swamped. I've extracted what I think are the relevant pieces of our applications and posted it here: https://github.com/seandstewart/memleak-example Important bits:
|
Thank you very much @seandstewart ! We'll review this with the team! |
Summary of problem
We noticed a huge memory leak after upgrading the
ddtrace
dependency in our application from v1.9.0 to v2.4.0. With Datadog tracing middleware enabled (trace_app(...)
), the memory footprint of the Python process keeps increasing as requests come in, and this keeps going and going until the process runs out of memory.Which version of dd-trace-py are you using?
Any version since v2.2.0 seems to exhibit the issue, and v2.1.9 does not.
Which version of pip are you using?
23.2.1
Which libraries and their versions are you using?
`pip freeze`
aiohttp==3.9.1 aiosignal==1.3.1 attrs==23.2.0 bytecode==0.15.1 cattrs==23.2.3 ddsketch==2.0.4 ddtrace==2.4.0 Deprecated==1.2.14 envier==0.5.0 frozenlist==1.4.1 idna==3.6 importlib-metadata==6.11.0 multidict==6.0.4 opentelemetry-api==1.22.0 protobuf==4.25.2 setuptools==69.0.3 six==1.16.0 typing_extensions==4.9.0 wrapt==1.16.0 xmltodict==0.13.0 yarl==1.9.4 zipp==3.17.0How can we reproduce your problem?
Install aiohttp (v3.9.1) and ddtrace, and then start the following trivial app:
Then keep hitting it with a lot of requests and watch the memory footprint grow in a linear fashion without bounds. On v2.1.9 and earlier, I've observed the memory footprint to plateau at around 44 MB.
What is the result that you get?
The memory footprint of the process grows without bounds.
What is the result that you expected?
The memory footprint plateaus after a while.
The text was updated successfully, but these errors were encountered: