Open TREVORPINKS opened 1 month ago
Interesting, yeah this code was changed under the assumption that null
would never be a value returned here, but I guess it is. Do you have some code that reproduces this issue?
Yes and No.
Here is what I was up to when I came across the issue. I was playing around with another component and I noticed after a simple code snippet my program wasn't returning to the command prompt. So... I added why-is-node-running and got the null reference error. So you can see from this post my output from why-is-node-running?
https://github.com/CheshireCaat/playwright-with-fingerprints/issues/44
basically it's code that launches hooks that listen for events and stuff. (FILEHANDLE, DNSCHANNEL and TTYWRAP) had the problems it seems. I don't have hello-world example type code to paste to you. I think for now just add that null check and at least it doesn't cause a fatal error.
I have same issue here, running in node test runner
We should probably test if isConstructor()
is false
before trying to get a file name.
Consider what happens when you:
import whyIsNodeRunning from 'why-is-node-running';
crypto.subtle
.generateKey('Ed25519', true, ['sign', 'verify'])
.then(key => {
console.log('Generated', key);
})
.finally(() => {
whyIsNodeRunning();
});
I logged around the problem area.
Generated [Object: null prototype] {
privateKey: CryptoKey {
type: 'private',
extractable: true,
algorithm: { name: 'Ed25519' },
usages: [ 'sign' ]
},
publicKey: CryptoKey {
type: 'public',
extractable: true,
algorithm: { name: 'Ed25519' },
usages: [ 'verify' ]
}
}
There are 4 handle(s) keeping the process running.
getFileName node:internal/async_hooks
getLineNumber 202
getColumnNumber 43
getFunctionName emitInitNative
getMethodName null
getTypeName NidKeyPairGenJob
isNative false
isConstructor false
getFileName node:internal/crypto/keygen
getLineNumber 301
getColumnNumber 14
getFunctionName createJob
getMethodName null
getTypeName null
isNative false
isConstructor false
getFileName node:internal/crypto/keygen
getLineNumber 85
getColumnNumber 15
getFunctionName generateKeyPair
getMethodName null
getTypeName null
isNative false
isConstructor false
getFileName node:internal/util
getLineNumber 431
getColumnNumber 7
getFunctionName null
getMethodName null
getTypeName null
isNative false
isConstructor false
getFileName null
getLineNumber null
getColumnNumber null
getFunctionName Promise
getMethodName null
getTypeName null
isNative false
isConstructor true
/home/sol/src/solana-web3.js-git/node_modules/.pnpm/why-is-node-running@3.2.0/node_modules/why-is-node-running/index.js:58
return !stack.getFileName().startsWith('node:')
^
TypeError: Cannot read properties of null (reading 'startsWith')
at <anonymous> (/home/sol/src/solana-web3.js-git/node_modules/.pnpm/why-is-node-running@3.2.0/node_modules/why-is-node-running/index.js:58:31)
at Array.filter (<anonymous>)
at printStacks (/home/sol/src/solana-web3.js-git/node_modules/.pnpm/why-is-node-running@3.2.0/node_modules/why-is-node-running/index.js:49:39)
at whyIsNodeRunning (/home/sol/src/solana-web3.js-git/node_modules/.pnpm/why-is-node-running@3.2.0/node_modules/why-is-node-running/index.js:44:5)
at <anonymous> (/home/sol/src/solana-web3.js-git/packages/library/test.ts:9:9)
at <anonymous>
Node.js v20.16.0
printStacks throws a null reference error within index.js when stack.getFileName() method returns null.
BEFORE: function printStacks (asyncResource, logger) { const stacks = asyncResource.stacks.filter((stack) => !stack.getFileName().startsWith('node:'))
THE FIX: function printStacks (asyncResource, logger) { const stacks = asyncResource.stacks.filter(stack => stack.getFileName() && !stack.getFileName().startsWith('node:'));
Original output: Null Ref Exception
New output:
FILEHANDLE
(unknown stack trace)
I am still trying to figure out if I can get a better error message here but wanted to report/share in the mean time.