doc icon indicating copy to clipboard operation
doc copied to clipboard

The value of "val" is out of range.

Open andrewpuch opened this issue 1 year ago • 1 comments

Hello,

I've been seeing some intermittent failures with this error.

The value of "val" is out of range. It must be a safe integer greater than 0. Received 0

Based on the stack trace it's coming from here.

https://github.com/dnlup/doc/blob/next/lib/gc.js#L71

The code I have that should be throwing the error is simplified here.

const doc = require('@dnlup/doc');

const sampler = doc({
  collect: {
    gc: true,
    cpu: false,
    memory: false,
    resourceUsage: false,
    eventLoopDelay: false,
    eventLoopUtilization: false,
    activeHandles: false,
  },
});

sampler.on('sample', () => {
  // Other functionality here
});

Is there something on my end that could be wrong and causing this error to be thrown intermittently? It's not easily reproducible.

Thank you.

andrewpuch avatar May 10 '24 17:05 andrewpuch

Hi @andrewpuch sorry to get back to you so late, what's your version of Node? Maybe there's something that needs better handling in the gc metrics with new versions.

dnlup avatar Aug 28 '24 06:08 dnlup

@dnlup I didn't see your notification. I tested the same on Node 18 / 20.

andrewpuch avatar Nov 12 '24 21:11 andrewpuch

I thought about what might be happening here and I think that when this error occurs we have a value of 0.<something> nanoseconds that becomes 0 because the value in a histogram has to be an integer and we truncate it.

I think it could be safe to assume that in cases like this we could avoid registering that entry in the histogram. If we want to be very meticulous, in cases where the value is >= 0.5 we could register 1. It is indeed hard to catch this in tests.

@andrewpuch What do you think?

dnlup avatar Dec 04 '24 08:12 dnlup

@dnlup I'm okay with that. I think that's a good compromise.

andrewpuch avatar Dec 05 '24 01:12 andrewpuch

@dnlup 👋 checking to see if you were able to make any progress on this. Thanks!

andrewpuch avatar Feb 06 '25 19:02 andrewpuch

Hi @andrewpuch sorry not yet, I am planning to do so this upcoming week.

dnlup avatar Feb 14 '25 12:02 dnlup