Skip to content

Fail to start application when using Microsoft.Extensions.Diagnostics.ResourceMonitoring on WSL #7748

Description

@mattsnowman

Description

When adding resource monitoring with services.AddResourceMonitoring(), the application fails to start with the following error message on WSL (Ubuntu 24.04):

System.InvalidOperationException: 'The total memory usage read from '/sys/fs/cgroup/memory.current' is lesser than inactive memory read from '/sys/fs/cgroup/memory.stat'.'

Debugging the method LinuxUtilizationParserCgroupV2.GetMemoryUsageInBytes, revealed that the memory usage is not read from /sys/fs/cgroup/memory.current (which does not exist) but from sys/fs/cgroup/user.slice/memory.current and /sys/fs/cgroup/system.slice/memory.current.

The calculated total memory usage is then a large negative number, which seems to be odd.
Example:
inactive memory: 492773376
memory usage: 140439552
140439552 - 492773376 = -352333824

Reproduction Steps

Start a .NET application which uses Microsoft.Extensions.Diagnostics.ResourceMonitoring on WSL (maybe only with Ubuntu 24.04?).

Expected behavior

  1. No exception to be thrown.
  2. The exception message should show the correct path/file name of the actually read memory.current files.

Actual behavior

An InvalidOperationException is thrown and the exception message is displaying the wrong path of the actually read memory.current files.

Regression?

No response

Known Workarounds

No.

Configuration

WSL version: 2.7.12.0 with .NET SDK 10.0.111
Running on Windows 11 (25H2 (OS Build 26200.9106)

Other information

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue describes a behavior which is not expected - a bug.untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions