src: map UINT64_MAX to 0 in process.constrainedMemory()#62209
src: map UINT64_MAX to 0 in process.constrainedMemory()#62209crawfordxx wants to merge 2 commits intonodejs:mainfrom
Conversation
|
|
||
| static void GetConstrainedMemory(const FunctionCallbackInfo<Value>& args) { | ||
| uint64_t value = uv_get_constrained_memory(); | ||
| if (value == UINT64_MAX) value = 0; |
There was a problem hiding this comment.
Can you add a comment explaining this? Can this be tested?
There was a problem hiding this comment.
Good point. I'll add an inline comment explaining the UINT64_MAX check.
For testing — this is tricky to unit test because uv_get_constrained_memory() depends on cgroup configuration at the OS level. On a system with cgroups enabled but no memory limit set (e.g. a default Docker container without --memory), the function returns UINT64_MAX. We could potentially add a test that mocks the libuv return value, but that would require refactoring to accept a dependency. Would a simple inline comment be sufficient, or would you prefer a test approach?
When uv_get_constrained_memory() returns UINT64_MAX, it indicates there is a constraining mechanism but no constraint is set. Per the Node.js documentation, this should return 0 instead of exposing the raw UINT64_MAX value to JavaScript. Fixes: nodejs#59227
bc6105e to
d062f4e
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62209 +/- ##
==========================================
+ Coverage 89.63% 89.66% +0.02%
==========================================
Files 676 676
Lines 206578 206452 -126
Branches 39555 39523 -32
==========================================
- Hits 185171 185105 -66
+ Misses 13535 13488 -47
+ Partials 7872 7859 -13
🚀 New features to boost your workflow:
|
Summary
When
uv_get_constrained_memory()returnsUINT64_MAX, it indicates there is a constraining mechanism (e.g., cgroups on Linux) but no constraint is actually set. According to the Node.js documentation, this case should return0:Currently, the raw
UINT64_MAXvalue (18446744073709552000as a double) is exposed to JavaScript, which contradicts the documented behavior.Changes
GetConstrainedMemory(), check ifuv_get_constrained_memory()returnsUINT64_MAXand map it to0<cstdint>include to ensureUINT64_MAXis definedReferences
Fixes: #59227