Skip to content

The Unix implementation of Process type is not thread safe #109434

@tmat

Description

@tmat

Description

Method GetWaitState() may be entered my multiple threads (it's not guarded by a lock) and each thread can return different instance of the ProcessWaitState, which is mutable.

{
if (_waitStateHolder == null)
{
EnsureState(State.HaveId);
_waitStateHolder = new ProcessWaitState.Holder(_processId);
}
return _waitStateHolder._state;
}

When using Process.Kill in dotnet-watch we observed that the method sometimes failed to terminate process on Linux. It is plausible that this is due to the above race condition.

Reproduction Steps

n/a

Expected behavior

All methods of Process type should be thread safe.

Actual behavior

Race conditions

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions