Skip to content

src: map UINT64_MAX to 0 in process.constrainedMemory()#62209

Open
crawfordxx wants to merge 2 commits intonodejs:mainfrom
crawfordxx:fix-constrained-memory-uint64max
Open

src: map UINT64_MAX to 0 in process.constrainedMemory()#62209
crawfordxx wants to merge 2 commits intonodejs:mainfrom
crawfordxx:fix-constrained-memory-uint64max

Conversation

@crawfordxx
Copy link

Summary

When uv_get_constrained_memory() returns UINT64_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 return 0:

If there is no constraint, or the constraint is unknown, 0 is returned.

Currently, the raw UINT64_MAX value (18446744073709552000 as a double) is exposed to JavaScript, which contradicts the documented behavior.

Changes

  • In GetConstrainedMemory(), check if uv_get_constrained_memory() returns UINT64_MAX and map it to 0
  • Added <cstdint> include to ensure UINT64_MAX is defined

References

Fixes: #59227

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Mar 11, 2026

static void GetConstrainedMemory(const FunctionCallbackInfo<Value>& args) {
uint64_t value = uv_get_constrained_memory();
if (value == UINT64_MAX) value = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining this? Can this be tested?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@crawfordxx crawfordxx force-pushed the fix-constrained-memory-uint64max branch from bc6105e to d062f4e Compare March 12, 2026 01:14
@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.66%. Comparing base (9ff27fd) to head (fd33a53).
⚠️ Report is 11 commits behind head on main.

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     
Files with missing lines Coverage Δ
src/node_process_methods.cc 88.20% <100.00%> (+0.02%) ⬆️

... and 35 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

process.constrainedMemory() should map UINT64_MAX to 0, per node documentation

3 participants