Skip to content

Possibly incorrect fd assertion in pal_utilities.h #131506

Closed

Description

@kg-unity3d

Description

This assertion:

assert(0 <= fd && fd < sysconf(_SC_OPEN_MAX));

Is incorrect because the value of _SC_OPEN_MAX can change during execution via setrlimit, and other processes can set your rlimit so it can change even if the application code never changes it. I think it should be simplified to assert(0 <= fd). As a bonus, that would probably make it possible to enable the assertion on WASI.

Reproduction Steps

The equivalent of this in C#:

struct rlimit rl = { 4096, 4096 };
setrlimit(RLIMIT_NOFILE, &rl);
int fd = dup2(0, 3000);
rl.rlim_cur = 1024;
setrlimit(RLIMIT_NOFILE, &rl);
assert(fd < sysconf(_SC_OPEN_MAX));

Would make this assertion fail.

Expected behavior

The assertion should only reject definitely-invalid fds like -1. The linux kernel's maximum valid FD is currently 1024*1024 but I wouldn't personally hard-code that into a runtime assertion.

Actual behavior

Any valid FD over the current rlimit will cause this assertion to fail.

Regression?

Not a regression.

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Jul 28, 2026
  2. added and removed
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Jul 29, 2026
  3. dotnet-policy-service commented on Jul 29, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-io
    See info in area-owners.md if you want to be subscribed.

  4. added this to the 11.0.0 milestone on Aug 11, 2026
  5. linked a pull request that will close this issueFix Unix file descriptor assertion #132136on Aug 11, 2026
  6. self-assigned this
    on Aug 11, 2026
  7. added a commit that references this issue on Aug 12, 2026
    98e33f5
  8. locked and limited conversation to collaborators on Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions