Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Including appmetrics breaks promisified setTimeout #634

Open
CherryDT opened this issue Mar 14, 2020 · 1 comment
Open

Including appmetrics breaks promisified setTimeout #634

CherryDT opened this issue Mar 14, 2020 · 1 comment

Comments

@CherryDT
Copy link

CherryDT commented Mar 14, 2020

node v12.10.0, appmetrics v5.1.1

Test case:

'use strict'

const { promisify } = require('util')
const delay = promisify(setTimeout)

async function main () {
  console.log('Hello...')
  await delay(1000)
  console.log('...world!')
}

main().then(() => process.exit(0), e => { console.error(e); process.exit(1) })

Result without appmetrcis:

david@CHE-X1:~/z/Temp/appmetrics-test $ node index.js 
Hello...
...world!

Result with appmetrics:

david@CHE-X1:~/z/Temp/appmetrics-test $ node --require appmetrics/start index.js
[Sat Mar 14 16:15:16 2020] com.ibm.diagnostics.healthcenter.loader INFO: Node Application Metrics 5.1.1.202003141613 (Agent Core 4.0.5)
[Sat Mar 14 16:15:16 2020] com.ibm.diagnostics.healthcenter.mqtt INFO: Connecting to broker localhost:1883
Hello...
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received 1000
    at setTimeout (timers.js:118:11)
    at fallback (/mnt/c/Users/david/Temp/appmetrics-test/node_modules/async-listener/index.js:621:15)
    at /mnt/c/Users/david/Temp/appmetrics-test/node_modules/async-listener/index.js:651:53
    at internal/util.js:277:30
    at new WrappedPromise (/mnt/c/Users/david/Temp/appmetrics-test/node_modules/async-listener/es6-wrapped-promise.js:13:18)
    at internal/util.js:276:12
    at main (/mnt/c/Users/david/Temp/appmetrics-test/index.js:8:9)
    at Object.<anonymous> (/mnt/c/Users/david/Temp/appmetrics-test/index.js:12:1)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)

It seems as if for some reason promisify would not respect setTimeout's custom util.promisify.custom handler in this case!

EDIT: After further testing, it seems that after including appmetrics/start, for some reason setTimeout and setImmediate are now missing the util.promisify.custom symbol property entirely! Also, confusingly, this does not happen when I do it from a node REPL.

@BannerBomb
Copy link

BannerBomb commented Apr 20, 2020

Same here for Node v13.0.1. But it's the async-listener package that's causing this since it's overriding the core Promise class with a custom one WrappedPromise.

`-- appmetrics@5.1.1
  `-- ibmapm-embed@20.3.0
    `-- zipkin-context-cls@0.6.1
      `-- continuation-local-storage@3.2.1
        `-- async-listener@0.6.10

this is the dependency package list for which package requires what ending at the async-listener package.

But as a work around you can try using

const wait = ms => new Promise(_ => setTimeout(_, ms));

instead of the promisify package on setTimeout

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

No branches or pull requests

2 participants