Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#endif

#include <climits> // PATH_MAX
#include <cstdint> // UINT64_MAX
#include <cstdio>

#if defined(_MSC_VER)
Expand Down Expand Up @@ -250,6 +251,12 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {

static void GetConstrainedMemory(const FunctionCallbackInfo<Value>& args) {
uint64_t value = uv_get_constrained_memory();
// When cgroups are enabled but no memory limit is set (e.g. a default
// Docker container without --memory), libuv returns UINT64_MAX instead of 0.
// UINT64_MAX is not a meaningful memory constraint, so map it to 0 to
// indicate "no constraint", consistent with the documented behavior of
// process.constrainedMemory(): "If there is no constraint, 0 is returned."
if (value == UINT64_MAX) value = 0;
args.GetReturnValue().Set(static_cast<double>(value));
}

Expand Down
Loading