Skip to content

Failing to create a thread shouldn't assume that this an out of memory issue #71761

Open

Description

@ayende

Description

The code here:

https://github.com/dotnet/runtime/blob/main/src/coreclr/vm/threads.cpp#L812

Assumes that failing to create a thread means that we run out of memory.
This result in this error:

---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Threading.Thread.StartInternal(ThreadHandle t, Int32 stackSize, Int32 priority, Char* pThreadName)
   at System.Threading.Thread.StartCore()

On Linux, there are few other options, such as the TasksMax limit (at process or user level), global number of processes limit at the kernel level.

Reproduction Steps

Set a low TasksMax limit and create more threads than allowed.

Expected behavior

Getting an error saying that the thread failed to start, and either pointing the actual reason for that or listing the various options.

Actual behavior

Getting a misleading exception pointing in the wrong direction.

Regression?

No response

Known Workarounds

No response

Configuration

Linux - systemd

In particular, running a server which spawns threads on need. You'll get OutOfMemoryException even if you have lots of room available.

Other information

No response

Activity

  1. ghost added
    untriaged
    on Jul 7, 2022
  2. removed
    untriaged
    on Jul 7, 2022
  3. added this to the 8.0.0 milestone on Jul 7, 2022
  4. modified the milestones: 8.0.0, Future on Jul 3, 2023
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions