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

async_hooks: AsyncLocalStorage store does not get GC. #54351

Closed
mcollina opened this issue Aug 13, 2024 · 3 comments
Closed

async_hooks: AsyncLocalStorage store does not get GC. #54351

mcollina opened this issue Aug 13, 2024 · 3 comments

Comments

@mcollina
Copy link
Member

mcollina commented Aug 13, 2024

For some unknown reasons, AsyncLocalStorage store object does not get gc'ed correctly:

'use strict'

const { test } = require('node:test')
const { AsyncLocalStorage } = require('node:async_hooks')
const { setImmediate } = require('node:timers/promises')
const assert = require('node:assert')

test('clone body garbage collection', async () => {
  const asyncLocalStorage = new AsyncLocalStorage()
  let ref = new WeakRef(new Map())

  await asyncLocalStorage.run(ref.deref(), async () => {})

  for (let i = 0; i < 1000; i++) {
    await setImmediate()
    global.gc(true)
  }

  assert.equal(ref.deref(), undefined, 'store was not garbage collected')
})

This test fails.

@mcollina
Copy link
Member Author

cc @Qard @legendecas

@mcollina
Copy link
Member Author

mcollina commented Aug 13, 2024

Closing, the test does not prove anything, as the following fails as well:

'use strict'

const { test } = require('node:test')
const { AsyncLocalStorage } = require('node:async_hooks')
const { setImmediate } = require('node:timers/promises')
const assert = require('node:assert')

test('clone body garbage collection', async () => {
  const asyncLocalStorage = new AsyncLocalStorage()
  let ref = new WeakRef(new Map())

  // await asyncLocalStorage.run(ref.deref(), async () => {})

  for (let i = 0; i < 1000; i++) {
    await setImmediate()
    global.gc(true)
  }

  assert.equal(ref.deref(), undefined, 'store was not garbage collected')
})

@mcollina mcollina closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2024
@Jamesernator
Copy link

Jamesernator commented Aug 13, 2024

Closing, the test does not prove anything, as the following fails as well:

The reason is global.gc(true) doesn't do a full collection, calling global.gc() instead passes the test as expected.

If this is meant to be a minimal replication of a AsyncLocalStorage holding things longer than it should, see this other issue I found with it.

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

No branches or pull requests

2 participants