Skip to content

Conversation

MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented Aug 22, 2025

Fixes #82719

Cc @dotnet/ilc-contrib

@Copilot Copilot AI review requested due to automatic review settings August 22, 2025 12:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR consolidates file descriptor limit handling across .NET runtime components by moving the descriptor limit increase functionality from individual runtime implementations into the shared minipal library. This ensures consistent behavior across CoreCLR, Mono, and Native AOT executables.

Key changes:

  • Creates a unified minipal_increase_descriptor_limit() function in the minipal library
  • Removes duplicate descriptor limit code from CoreCLR PAL and Mono runtime
  • Adds descriptor limit increase functionality to Native AOT bootstrap

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/native/minipal/descriptorlimit.h New header defining the minipal descriptor limit API
src/native/minipal/descriptorlimit.c New implementation of descriptor limit increase functionality
src/native/minipal/minipalconfig.h.in Adds HAVE_RESOURCE_H configuration check
src/native/minipal/configure.cmake Adds sys/resource.h availability check
src/native/minipal/CMakeLists.txt Includes new descriptor limit source and disables functionality on problematic platforms
src/mono/mono/mini/driver.c Replaces local descriptor limit function with minipal version
src/mono/CMakeLists.txt Removes redundant DONT_SET_RLIMIT_NOFILE definition
src/coreclr/pal/src/init/pal.cpp Replaces local descriptor limit function with minipal version
src/coreclr/pal/src/CMakeLists.txt Removes redundant DONT_SET_RLIMIT_NOFILE definition
src/coreclr/nativeaot/Bootstrap/main.cpp Adds descriptor limit increase call to Native AOT bootstrap

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@pavelsavara
Copy link
Member

pavelsavara commented Aug 26, 2025

Unfortunately we don't run WASI builds on PRs anymore and (I think) this broke the build.

Log

  FAILED: mono/minipal/minipal/CMakeFiles/minipal_objects.dir/descriptorlimit.c.obj 
  D:\a\_work\1\s\src\mono\wasi\wasi-sdk\bin\clang.exe --target=wasm32-wasip2 --sysroot=D:/a/_work/1/s/src/mono/wasi/wasi-sdk/share/wasi-sysroot -DCOMPILER_SUPPORTS_W_RESERVED_IDENTIFIER -DDISABLE_EGD_SOCKET -DDISABLE_EVENTPIPE -DHAVE_CONFIG_H -DHOST_WASI -D_THREAD_SAFE -D_WASI_EMULATED_MMAN -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_PTHREAD -D_WASI_EMULATED_SIGNAL -ID:/a/_work/1/s/artifacts/obj -ID:/a/_work/1/s/src/native -ID:/a/_work/1/s/artifacts/obj/mono/wasi.wasm.Release/mono/minipal/minipal "-ID:/a/_work/1/s/src/mono/wasi/include" "-ID:/a/_work/1/s/src/mono/wasi/mono-include" "-ID:/a/_work/1/s/src/native/public" "-ID:/a/_work/1/s/src/mono/mono/eglib" -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -D_WASI_EMULATED_PTHREAD -fno-strict-aliasing -fwrapv -Wall -Wunused -Wmissing-declarations -Wpointer-arith -Wno-cast-qual -Wwrite-strings -Wno-switch -Wno-switch-enum -Wno-unused-value -Wno-attributes -Wno-format-zero-length -Wno-unused-function -Qunused-arguments -Wno-tautological-compare -Wno-parentheses-equality -Wno-self-assign -Wno-return-stack-address -Wno-constant-logical-operand -Wno-zero-length-array -Wno-asm-operand-widths -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Werror=return-type -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Wno-incompatible-pointer-types-discards-qualifiers -Werror -O3 -DNDEBUG -std=gnu11   -g -fPIC -fvisibility=hidden -Wno-strict-prototypes -Wno-unused-but-set-variable -Os -ffp-contract=off -MD -MT mono/minipal/minipal/CMakeFiles/minipal_objects.dir/descriptorlimit.c.obj -MF mono\minipal\minipal\CMakeFiles\minipal_objects.dir\descriptorlimit.c.obj.d -o mono/minipal/minipal/CMakeFiles/minipal_objects.dir/descriptorlimit.c.obj -c D:/a/_work/1/s/src/native/minipal/descriptorlimit.c
  D:/a/_work/1/s/src/native/minipal/descriptorlimit.c:21:19: error: variable has incomplete type 'struct rlimit'
     21 |     struct rlimit rlp;
        |                   ^
  D:/a/_work/1/s/src/native/minipal/descriptorlimit.c:21:12: note: forward declaration of 'struct rlimit'
     21 |     struct rlimit rlp;
        |            ^
  D:/a/_work/1/s/src/native/minipal/descriptorlimit.c:24:14: error: call to undeclared function 'getrlimit'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     24 |     result = getrlimit(RLIMIT_NOFILE, &rlp);
        |              ^
  D:/a/_work/1/s/src/native/minipal/descriptorlimit.c:24:24: error: use of undeclared identifier 'RLIMIT_NOFILE'
     24 |     result = getrlimit(RLIMIT_NOFILE, &rlp);
        |                        ^
  D:/a/_work/1/s/src/native/minipal/descriptorlimit.c:40:14: error: call to undeclared function 'setrlimit'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     40 |     result = setrlimit(RLIMIT_NOFILE, &rlp);
        |              ^
  D:/a/_work/1/s/src/native/minipal/descriptorlimit.c:40:24: error: use of undeclared identifier 'RLIMIT_NOFILE'
  
     40 |     result = setrlimit(RLIMIT_NOFILE, &rlp);
  
        |                        ^

I filled #119100

@MichalStrehovsky
Copy link
Member Author

MichalStrehovsky commented Aug 26, 2025

Unfortunately we don't run WASI builds on PRs anymore and (I think) this broke the build.

Sorry about that, I expected this to cover it:

#if TARGET_WASM
// WebAssembly cannot set limits
#elif TARGET_LINUX_MUSL

But looks like we don't define TARGET_WASM there? Do we need TARGET_WASI instead? (I don't see that one defined in the failing clang command line either though).

@pavelsavara
Copy link
Member

@SingleAccretion volunteered to fix it here #116390 (comment)

@MichalStrehovsky
Copy link
Member Author

@SingleAccretion volunteered to fix it here #116390 (comment)

Sorry for the trouble. Should be an easy fix for someone who knows the right ifdef to gate against.

@jkotas
Copy link
Member

jkotas commented Aug 26, 2025

Unfortunately we don't run WASI builds on PRs anymore

@pavelsavara Is there a reason? It would be ok to run a WASI build in the CI to catch trivial build breaks like this (single flavor, build only, PRs only - no official builds). We do the same for number of other community supported platforms.

@pavelsavara
Copy link
Member

@pavelsavara Is there a reason?

The setup we had in Net9 was much broader, library unit tests, workload testing, native builds, there is also our own build of LLVM and ideally WASI-SDK to flow, wasmtime installations to helix ... we didn't have bandwidth to maintain it in Net10.

It would be ok to run a WASI build in the CI to catch trivial build breaks like this (single flavor, build only, PRs only - no official builds). We do the same for number of other community supported platforms.

Yes, we are discussing that with @lewing, perhaps I disabled too much of the above ?

@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increase file descriptor limit in NativeAOT app process

3 participants