Skip to content

stream: fix memory usage regression in writable - #53188

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
orgads:writable-temp-leak
Jun 2, 2024
Merged

stream: fix memory usage regression in writable#53188
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
orgads:writable-temp-leak

Conversation

@orgads

@orgadsorgads commented May 28, 2024

Copy link
Copy Markdown
Contributor

Setting writecb and afterWriteTickInfo to null did not clear the value in the state object.

Amends 35ec931 (stream: writable state bitmap).

Fixes#52228.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/streams

@nodejs-github-botnodejs-github-bot added the needs-ci PRs that need a full CI run. label May 28, 2024
@orgads

Copy link
Copy Markdown
ContributorAuthor

@ronag@mcollina

I'm not sure how to add a test for this. Hints will be welcome :)

I tested with the example app from #52228 and it seems to solve the issue.

@orgads

Copy link
Copy Markdown
ContributorAuthor

Actually the condition is equivalent. I'll need to dig deeper.

Comment threadlib/internal/streams/writable.js Outdated
@orgads

Copy link
Copy Markdown
ContributorAuthor

@ronag I tried to inspect that change, but couldn't find a smoking gun. #52228 is definitely caused by it, I bisected and triple-checked. Can you try to find the culprit?

I'm closing this PR, as it is wrong anyway.

@orgadsorgads closed this May 28, 2024
@orgadsorgads reopened this May 29, 2024
@orgads
orgadsforce-pushed the writable-temp-leak branch from eb34ffd to 7b9f16bCompareMay 29, 2024 05:53
@orgadsorgads changed the title writable: Fix condition mis-translationstream: fix memory leaks in writableMay 29, 2024
@orgads
orgadsforce-pushed the writable-temp-leak branch from 7b9f16b to 24b2499CompareMay 29, 2024 05:54
@orgads

Copy link
Copy Markdown
ContributorAuthor

Ok, I found the culprit. Ready for review.

Can you suggest how to add a test?

@benjamingr

Copy link
Copy Markdown
Member

Can you suggest how to add a test?

Good question, I'm honestly not so sure - you can test writecb is set to null in onwrite but I'm not sure that tests something useful. We don't have memory benchmarks I'm aware of though that might be a good idea overall.

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

However this is not a memory leak, because the memory consumption is stable.
I would recommend we change the commit/PR title to "stream: fix memory usage regression in writable".

@mcollina

Copy link
Copy Markdown
Member

A test for this would be nice but I'm at a loss on how to write it.

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label May 29, 2024
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 29, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@orgads
orgadsforce-pushed the writable-temp-leak branch from 24b2499 to aec133fCompareMay 29, 2024 14:33
@orgadsorgads changed the title stream: fix memory leaks in writablestream: fix memory usage regression in writableMay 29, 2024
@orgads

Copy link
Copy Markdown
ContributorAuthor

However this is not a memory leak, because the memory consumption is stable. I would recommend we change the commit/PR title to "stream: fix memory usage regression in writable".

Done.

@lpincalpinca added the request-ci Add this label to start a Jenkins CI on a PR. label May 29, 2024
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 29, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Setting writecb and afterWriteTickInfo to null did not clear the value
in the state object.
Amends 35ec931 (stream: writable state bitmap).
Fixesnodejs#52228.
@orgads
orgadsforce-pushed the writable-temp-leak branch from aec133f to 61da0edCompareMay 30, 2024 09:55
@lpincalpinca added the request-ci Add this label to start a Jenkins CI on a PR. label May 30, 2024
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 30, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@orgads

Copy link
Copy Markdown
ContributorAuthor

smartos build fails, unrelated to my changes.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@H4adH4ad added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 2, 2024
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 2, 2024
@nodejs-github-bot
nodejs-github-bot merged commit 78a326e into nodejs:mainJun 2, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 78a326e

@orgads
orgads deleted the writable-temp-leak branch June 2, 2024 01:38
@orgads

Copy link
Copy Markdown
ContributorAuthor

Thanks! What's the process of backporting? Should I cherry pick and create a new PR for 22 and 20?

@H4ad

H4ad commented Jun 2, 2024

Copy link
Copy Markdown
Member

@orgads Since we didn't put labels like "do not land", this PR is automatically eligible to be included in older versions, just wait for the next version, the releasers will include this PR.

You only need to create backport when releasers find a conflict that doesn't allow them merge it easily.

/cc @nodejs/releasers Just to let you know guys an important fix for memory usage on streams was merged.

targos pushed a commit that referenced this pull request Jun 3, 2024
Setting writecb and afterWriteTickInfo to null did not clear the value
in the state object.
Amends 35ec931 (stream: writable state bitmap).
Fixes#52228.
PR-URL: #53188
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
@RafaelGSSRafaelGSS mentioned this pull request Jun 7, 2024
eliphazbouye pushed a commit to eliphazbouye/node that referenced this pull request Jun 20, 2024
Setting writecb and afterWriteTickInfo to null did not clear the value
in the state object.
Amends 35ec931 (stream: writable state bitmap).
Fixesnodejs#52228.
PR-URL: nodejs#53188
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
@orgads

Copy link
Copy Markdown
ContributorAuthor

@H4ad@marco-ippolito It hasn't been backported to 20.x. :(

@marco-ippolito

Copy link
Copy Markdown
Member

@H4ad@marco-ippolito It hasn't been backported to 20.x. :(

It has not been on the Current enough (2 weeks) to be backported to v20

@orgads

Copy link
Copy Markdown
ContributorAuthor

I see. Thanks for the explanation.

marco-ippolito pushed a commit that referenced this pull request Jul 19, 2024
Setting writecb and afterWriteTickInfo to null did not clear the value
in the state object.
Amends 35ec931 (stream: writable state bitmap).
Fixes#52228.
PR-URL: #53188
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
@marco-ippolitomarco-ippolito mentioned this pull request Jul 19, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Significant memory usage increase starting from 20.10.0 for a simple HTTP server (potentially stream related)

7 participants

@orgads@nodejs-github-bot@benjamingr@mcollina@H4ad@marco-ippolito@lpinca