The Unix implementation of Process type is not thread safe

Open
#109,434 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp

Research direction

Start in src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs at GetWaitState(), especially lines 955-962, then trace how Process.Kill uses the returned ProcessWaitState. Reproduce or reason about concurrent calls and verify that concurrent Process operations no longer observe separate mutable state or fail to terminate the process.

Written by the indexing model from the issue text.

Description

area-System.Diagnostics.Process needs-further-triage
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.

https://github.com/dotnet/runtime/blob/97f50455530cfbe21d28544d2b3fb14611f4ae7a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs#L955-L962

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

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.