The value of "val" is out of range.
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.
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 I didn't see your notification. I tested the same on Node 18 / 20.
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 I'm okay with that. I think that's a good compromise.
@dnlup 👋 checking to see if you were able to make any progress on this. Thanks!
Hi @andrewpuch sorry not yet, I am planning to do so this upcoming week.