Excessive exceptions in NamedPipeClientStream on Linux when connecting to a non-existent target
#117,718 opened on Jul 16, 2025
Description
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