Skip to content

Excessive exceptions in NamedPipeClientStream on Linux when connecting to a non-existent target #117718

Closed

Description

@lindexi

Description

When using NamedPipeClientStream on Linux to connect to a non-existent target, the .NET runtime continuously throws SocketException internally, which severely impacts performance.

Reproduction Steps

The issue can be reproduced with the following simple code:

using System.IO.Pipes;

AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) =>
{
    Console.WriteLine($"FirstChanceException: {eventArgs.Exception.GetType().FullName} {eventArgs.Exception.Message}");
};

var namedPipeClientStream = new NamedPipeClientStream("DoNotExistFoo");
namedPipeClientStream.Connect();

You can find my code in https://github.com/lindexi/lindexi_gd/tree/31318b24ff8656a05f0f81bef867b501e425d6bf/Workbench/BeekefanereHawgudairwochemwhi

When running the above code on a Linux system, you will notice that AppDomain.CurrentDomain.FirstChanceException is triggered excessively, and the console is flooded with output.

Expected behavior

I am not sure. But at least, it should not throw exceptions at a high frequency.

Actual behavior

We can find the AppDomain.CurrentDomain.FirstChanceException is triggered excessively. The console output is: FirstChanceException: System.Net.Sockets.SocketException Cannot assign requested address /tmp/CoreFxPipe_DoNotExistFoo

The exception is:

System.Net.Sockets.SocketException (99): Cannot assign requested address /tmp/CoreFxPipe_DoNotExistFoo
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)

The stacktrace is

  System.Net.Sockets.dll!System.Net.Sockets.Socket.DoConnect(System.Net.EndPoint endPointSnapshot, System.Net.SocketAddress socketAddress)  C#
  System.Net.Sockets.dll!System.Net.Sockets.Socket.Connect(System.Net.EndPoint remoteEP)  C#
  System.IO.Pipes.dll!System.IO.Pipes.NamedPipeClientStream.TryConnect(int _) C#
  System.IO.Pipes.dll!System.IO.Pipes.NamedPipeClientStream.ConnectInternal(int timeout = -1, System.Threading.CancellationToken cancellationToken, int startTime = 542050485)  C#
> BeekefanereHawgudairwochemwhi.dll!Program.<Main>$(string[] args = {string[0]}) line 21 C#

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Jul 16, 2025
  2. added
    needs-area-label
    on Jul 16, 2025
  3. added and removed
    needs-area-label
    on Jul 16, 2025
  4. dotnet-policy-service commented on Jul 16, 2025

    @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.

  5. added
    help wanted
    and removed
    untriaged
    on Jul 22, 2025
  6. added this to the Future milestone on Jul 22, 2025
  7. added a commit that references this issue on Mar 20, 2026
    03a1465
  8. added a commit that references this issue on Jul 19, 2026
    ec6dd81
  9. locked and limited conversation to collaborators on Aug 18, 2026
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

    area-System.IOhelp wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions