GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — diagnostics_channel: fix diagnostics channel memory leak by theanarkh · Pull Request #45633 · nodejs/node

Conversation

@theanarkh

@theanarkh theanarkh commented Nov 26, 2022 •
edited by VoltrexKeyva
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

fix diagnostics channel memory leak.
cc @Qard

const { subscribe, unsubscribe } = require('diagnostics_channel');

function noop() {}

console.log(process.memoryUsage().heapUsed);

for (let i = 0; i < 1000000; i++) {
    subscribe(String(i), noop);
    unsubscribe(String(i), noop);
}

gc();

console.log(process.memoryUsage().heapUsed);
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss and cuihairu reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Nov 26, 2022
Qard
Qard approved these changes Nov 26, 2022
View reviewed changes
@theanarkh
theanarkh force-pushed the fix_diagnostics_channel_memory_leak branch from ae3c2f9 to 2026e9c Compare November 26, 2022 19:21
@Qard

Qard commented Nov 26, 2022

Copy link
Copy Markdown
Member

LGTM. Not really how users are intended to use diagnostics_channel, but how users are meant to use things and how they actually use them doesn't always match, so seems like a reasonable fix to me. 😅

anonrig reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anonrig
anonrig approved these changes Nov 27, 2022
View reviewed changes

@anonrig anonrig left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@theanarkh theanarkh added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 27, 2022
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 27, 2022
@nodejs-github-bot

nodejs-github-bot commented Nov 27, 2022

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/48203/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen

RaisinTen commented Nov 27, 2022

Copy link
Copy Markdown
Member

Could you add a test for this? Maybe by comparing the values of process.memoryUsage().heapUsed before and after the loop and gc call?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell approved these changes Nov 27, 2022
View reviewed changes
@theanarkh

theanarkh commented Nov 27, 2022

Copy link
Copy Markdown
Contributor Author

Could you add a test for this? Maybe by comparing the values of process.memoryUsage().heapUsed before and after the loop and gc call?

I think it is difficult to do that, do you have any idea? Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JungMinu
JungMinu approved these changes Nov 28, 2022
View reviewed changes
@RaisinTen

RaisinTen commented Nov 28, 2022

Copy link
Copy Markdown
Member

I think it is difficult to do that, do you have any idea? Thanks!

I meant using the code you shared in the PR description with a slight modification - asserting that the value of process.memoryUsage().heapUsed after the loop+gc is less than or equal to the value before. Like this:

// Flags: --expose-gc
'use strict';

// This test ensures that diagnostic channel references aren't leaked.

require('../common');
const { ok } = require('assert');

const { subscribe, unsubscribe } = require('diagnostics_channel');

function noop() {}

const heapUsedBefore = process.memoryUsage().heapUsed;

for (let i = 0; i < 1000000; i++) {
    subscribe(String(i), noop);
    unsubscribe(String(i), noop);
}

gc();

const heapUsedAfter = process.memoryUsage().heapUsed;

ok(heapUsedBefore >= heapUsedAfter);

Is it difficult because it's too flaky?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@theanarkh
theanarkh force-pushed the fix_diagnostics_channel_memory_leak branch from 2026e9c to cf83822 Compare November 28, 2022 14:37
RaisinTen
RaisinTen reviewed Nov 28, 2022
View reviewed changes
Comment thread test/parallel/test-diagnostics-channel-memory-leak.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@theanarkh
diagnostics_channel: fix diagnostics channel memory leak
4fb75ce
@theanarkh

theanarkh commented Nov 28, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion. When i add the test(i = 1000000), i find the output is as follows.

before gc 5350312
after  gc 15322320

But when i change the code channels[name] = null; to delete channels[name];, the output is as follows.

before gc 5353152
after  gc 4639440

Then i take the snapshot before and after the loop. I find It takes up ten more megabytes of memory in channels[name] = null;(But when i is 100, the output of two cases is the same) 😄.
image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@theanarkh
theanarkh force-pushed the fix_diagnostics_channel_memory_leak branch from cf83822 to 4fb75ce Compare November 28, 2022 15:02
RaisinTen
RaisinTen approved these changes Nov 28, 2022
View reviewed changes

@RaisinTen RaisinTen left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Qard
Qard approved these changes Nov 28, 2022
View reviewed changes
@theanarkh theanarkh added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 29, 2022
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 29, 2022
@nodejs-github-bot

nodejs-github-bot commented Nov 29, 2022

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/48229/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Nov 29, 2022

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/48231/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@theanarkh theanarkh added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 29, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 29, 2022
@nodejs-github-bot
nodejs-github-bot merged commit d579bc1 into nodejs:main Nov 29, 2022
@nodejs-github-bot

nodejs-github-bot commented Nov 29, 2022

Copy link
Copy Markdown
Collaborator

Landed in d579bc1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Nov 30, 2022
CI Reliability 2022-11-30 nodejs/reliability#444
Open
15 tasks
This was referenced Dec 1, 2022
CI Reliability 2022-12-01 nodejs/reliability#445
Open
CI Reliability 2022-12-02 nodejs/reliability#446
Open
CI Reliability 2022-12-03 nodejs/reliability#447
Open
CI Reliability 2022-12-04 nodejs/reliability#448
Open
CI Reliability 2022-12-05 nodejs/reliability#449
Open
CI Reliability 2022-12-07 nodejs/reliability#450
Open
targos pushed a commit that referenced this pull request Dec 12, 2022
@theanarkh @targos
diagnostics_channel: fix diagnostics channel memory leak
c527741
PR-URL: #45633
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
@targos targos mentioned this pull request Dec 12, 2022
v19.3.0 release proposal #45831
Merged
@danielleadams danielleadams mentioned this pull request Dec 30, 2022
v18.13.0 release proposal #46025
Merged
danielleadams pushed a commit that referenced this pull request Dec 30, 2022
@theanarkh @danielleadams
diagnostics_channel: fix diagnostics channel memory leak
4bf08d8
PR-URL: #45633
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
danielleadams pushed a commit that referenced this pull request Jan 3, 2023
@theanarkh @danielleadams
diagnostics_channel: fix diagnostics channel memory leak
1a47a7b
PR-URL: #45633
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
danielleadams pushed a commit that referenced this pull request Jan 5, 2023
@theanarkh @danielleadams
diagnostics_channel: fix diagnostics channel memory leak
6c1eb97
PR-URL: #45633
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Qard Qard Qard approved these changes
@jasnell jasnell jasnell approved these changes
@anonrig anonrig anonrig approved these changes
@JungMinu JungMinu JungMinu approved these changes
@RaisinTen RaisinTen RaisinTen approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@theanarkh @Qard @nodejs-github-bot @RaisinTen @jasnell @anonrig @JungMinu
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.