镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

perf_hooks.performance.timerify() with histogram: RangeError [ERR_OUT_OF_RANGE] on arm64 #41641

Description

@jonahsnider

Version

v14, v16, v17, v18, v26

Platform

macOS v12.4 (21F79).

Darwin 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 arm64

Subsystem

perf_hooks

What steps will reproduce the bug?

Run this snippet:

import {createHistogram, performance} from 'node:perf_hooks';

const fn = () => {};

const timerified = performance.timerify(fn, {histogram: createHistogram()});

for (let i = 0; i < 100_000; i++) {
	try {
		timerified();
	} catch (error) {
		console.error('Crashed on iteration', i);

		throw error;
	}
}

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

100% consistent reproduction, requires arm64, maybe requires macOS.

What is the expected behavior?

Calling the timerified function returned from perf_hooks.performance.timerify() should successfully record to the histogram.

What do you see instead?

node:internal/errors:466
    ErrorCaptureStackTrace(err);
    ^

RangeError [ERR_OUT_OF_RANGE]: The value of "val" is out of range. It must be a safe integer greater than 0. Received 0
    at new NodeError (node:internal/errors:377:5)
    at RecordableHistogram.record (node:internal/histogram:290:13)
    at processComplete (node:internal/perf/timerify:40:15)
    at timerified fn (node:internal/perf/timerify:88:5)
    at file:///Users/jonah/programming/benchmark/index.mjs:9:3
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async loadESM (node:internal/process/esm_loader:85:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12) {
  code: 'ERR_OUT_OF_RANGE'
}

Node.js v18.1.0

Additional information

Originally reported here: sindresorhus/yoctocolors#9 (comment)


The bug appears to be from the implementation of perf_hooks.performance.timerify() with a histogram, when calling the returned timerified function. The error comes from the input validation of RecordableHistogram#record(), attempting to record a value x < 1 will throw. For whatever reason timerify() seems to be recording an execution duration of 0 and trying to record that. See the error stacktrace for more info.

Activity

  1. benjamingr commented on Jan 22, 2022

    @benjamingr
    Member
  2. added
    perf_hooksIssues and PRs related to the perf_hooks module and performance measurement APIs.
    on Jan 22, 2022
  3. jonahsnider commented on May 28, 2022

    @jonahsnider
    ContributorAuthor

    I recently upgraded to an arm64 laptop and was able to update the description of this issue with more specific system details. I also fixed a bug in the provided snippet which caused the reported bug to never trigger.

    Additionally, I was able to reproduce this bug on Node.js v18.1.0.

  4. everett1992 commented on Oct 5, 2023

    @everett1992
    Contributor

    We're still seeing this with node 18.18

    https://github.com/nodejs/node/blob/v18.x/lib/internal/perf/timerify.js#L38-L40

    is there any guarantee that two calls to performance.now() will return a different value?

  5. github-actions commented on Jun 25, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  6. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 25, 2026
  7. jonahsnider commented on Jun 25, 2026

    @jonahsnider
    ContributorAuthor

    Still occurring for me on Node v26:

    Crashed on iteration 562
    node:internal/histogram:292
        validateInteger(val, 'val', 1);
        ^
    
    RangeError [ERR_OUT_OF_RANGE]: The value of "val" is out of range. It must be >= 1 && <= 9007199254740991. Received 0
        at RecordableHistogram.record (node:internal/histogram:292:5)
        at processComplete (node:internal/perf/timerify:40:15)
        at timerified fn (node:internal/perf/timerify:87:5)
        at file:///Users/jonah.snider/programming/node-bug-41641/index.mjs:9:3
        at ModuleJob.run (node:internal/modules/esm/module_job:439:25)
        at async node:internal/modules/esm/loader:646:26
        at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5) {
      code: 'ERR_OUT_OF_RANGE'
    }
    
    Node.js v26.3.0
    
  8. removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 26, 2026
  9. github-actions commented on Sep 25, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 90 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  10. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Sep 25, 2026
  11. jonahsnider commented on Sep 25, 2026

    @jonahsnider
    ContributorAuthor

    Still able to reproduce on v26.10.0:

    Crashed on iteration 2130
    node:internal/histogram:734
        validateInteger(val, 'val', 1);
        ^
    
    RangeError [ERR_OUT_OF_RANGE]: The value of "val" is out of range. It must be >= 1 && <= 9007199254740991. Received 0
        at RecordableHistogram.record (node:internal/histogram:734:5)
        at processComplete (node:internal/perf/timerify:40:15)
        at timerified fn (node:internal/perf/timerify:87:5)
        at file:///Users/jonah.snider/Downloads/test.js:9:3
        at ModuleJob.run (node:internal/modules/esm/module_job:569:25)
        at async node:internal/modules/esm/loader:650:26
        at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:105:5) {
      code: 'ERR_OUT_OF_RANGE'
    }
    
    Node.js v26.10.0
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    perf_hooksIssues and PRs related to the perf_hooks module and performance measurement APIs.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions