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

printStacks null reference error within index.js #81

Closed
TREVORPINKS opened this issue Sep 15, 2024 · 5 comments · Fixed by #82
Closed

printStacks null reference error within index.js #81

TREVORPINKS opened this issue Sep 15, 2024 · 5 comments · Fixed by #82
Labels

Comments

@TREVORPINKS
Copy link

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.

@jonkoops jonkoops added the bug label Sep 16, 2024
@jonkoops
Copy link
Collaborator

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?

@TREVORPINKS
Copy link
Author

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?

CheshireCaat/playwright-with-fingerprints#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.

@himself65
Copy link

I have same issue here, running in node test runner

@steveluscher
Copy link

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/[email protected]/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/[email protected]/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/[email protected]/node_modules/why-is-node-running/index.js:49:39)
    at whyIsNodeRunning (/home/sol/src/solana-web3.js-git/node_modules/.pnpm/[email protected]/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

jonkoops added a commit to jonkoops/why-is-node-running that referenced this issue Oct 29, 2024
jonkoops added a commit that referenced this issue Oct 29, 2024
@jonkoops
Copy link
Collaborator

jonkoops commented Oct 29, 2024

I've restored the old behavior of filtering out any unidentifiable file names and tagged a new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants