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

node:fs/promises - throw new ERR_INTERNAL_ASSERTION(message); #50720

Closed
fedgrant opened this issue Nov 14, 2023 · 2 comments
Closed

node:fs/promises - throw new ERR_INTERNAL_ASSERTION(message); #50720

fedgrant opened this issue Nov 14, 2023 · 2 comments

Comments

@fedgrant
Copy link

Version

v21.1.0

Platform

6.2.0-36-generic #37~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct 9 15:34:04 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

(async () => {
  const file = await open("./text.txt", 'a+')
  let count = 0
  while(count < 5) {
    await makeAppend(file.appendFile.bind(this))
    count++
  }
  await makeAppend(file.appendFile.bind(this))
  await file.close()
})();

async function makeAppend(appendFn) {
  console.log("here", appendFn) // <--- prints
  await appendFn(`hi there`)
  console.log("here") <-- doesn't make it here
}

How often does it reproduce? Is there a required condition?

I was able to reproduce on v18.x lts, all the way up to the current release.

What is the expected behavior? Why is that the expected behavior?

I would have expected to be able to pass the function from the fileHandler into another function.

What do you see instead?

here [Function: bound appendFile]
node:internal/assert:14
    throw new ERR_INTERNAL_ASSERTION(message);
          ^

Error [ERR_INTERNAL_ASSERTION]: handle must be an instance of FileHandle
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https:/nodejs/node/issues

    at assert (node:internal/assert:14:11)
    at fsCall (node:internal/fs/promises:431:3)
    at Object.appendFile (node:internal/fs/promises:156:12)
    at makeAppend (/home/fed/workspace/index.js:17:9)
    at /home/fed/workspace/index.js:8:11 {
  code: 'ERR_INTERNAL_ASSERTION'
}

Node.js v21.1.0

Additional information

If I run the file without the .bind(this) i get the following

here [Function: appendFile]
node:internal/fs/promises:431
  assert(handle[kRefs] !== undefined,
               ^

TypeError: Cannot read properties of undefined (reading 'Symbol(kRefs)')
    at fsCall (node:internal/fs/promises:431:16)
    at appendFile (node:internal/fs/promises:156:12)
    at makeAppend (/home/fed/workspace/index.js:17:9)
    at /home/fed/workspace/index.js:8:11

Node.js v21.1.0

script

(async () => {
  const file = await open("./text.txt", 'a+')
  let count = 0
  while(count < 5) {
    await makeAppend(file.appendFile)
    count++
  }
  await makeAppend(file.appendFile)
  await file.close()
})();

async function makeAppend(appendFn) {
  console.log("here", appendFn)
  await appendFn(`hi there`)
  console.log("here")
}
@pluris
Copy link
Contributor

pluris commented Nov 14, 2023

IMO, shouldn't we pass file instead of this to bind of appendFile?
It works fine after changing to this-> file.

(async () => {
  const file = await open("./text.txt", 'a+')
  let count = 0
  while(count < 5) {
    await makeAppend(file.appendFile.bind(file))
    count++
  }
  await makeAppend(file.appendFile.bind(file))
  await file.close()
})();

async function makeAppend(appendFn) {
  console.log("here", appendFn) // <--- prints
  await appendFn(`hi there`)
  console.log("here") <-- doesn't make it here
}
//Prints :
here [Function: bound appendFile]
here
here [Function: bound appendFile]
here
here [Function: bound appendFile]
here
here [Function: bound appendFile]
here
here [Function: bound appendFile]
here
here [Function: bound appendFile]
here

@fedgrant
Copy link
Author

That is fair that is probably the right approach. I originally got the second error first and was playing around with different ways to solve it and got the first error that said to report to node.

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