-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot reuse Unix Domain Socket on Windows #71291
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionOn Linux, Reproduction Steps[Fact]
public static async Task CannotReuseSocketRepro()
{
var path = new UnixDomainSocketEndPoint(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
// server
using var serverCts = new CancellationTokenSource();
var server = RunServer(path, serverCts.Token);
// client
using (var clientSocket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified))
{
var buffer = new byte[512];
await clientSocket.ConnectAsync(path);
var count = await clientSocket.ReceiveAsync(buffer, SocketFlags.None);
Equal("Hello", Encoding.UTF8.GetString(buffer, 0, count));
await clientSocket.DisconnectAsync(reuseSocket: true);
// on Linux the connection is successful here, on Windows - failure
await clientSocket.ConnectAsync(path);
count = await clientSocket.ReceiveAsync(buffer, SocketFlags.None);
Equal("Hello", Encoding.UTF8.GetString(buffer, 0, count));
await clientSocket.DisconnectAsync(reuseSocket: true);
}
serverCts.Cancel();
await server;
}
private static async Task RunServer(UnixDomainSocketEndPoint endPoint, CancellationToken token)
{
using var serverSocket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
serverSocket.Bind(endPoint);
serverSocket.Listen();
while (!token.IsCancellationRequested)
{
using var acceptedSocket = await serverSocket.AcceptAsync(token);
await acceptedSocket.SendAsync(Encoding.UTF8.GetBytes("Hello"), SocketFlags.None, token);
await acceptedSocket.DisconnectAsync(reuseSocket: false, token);
}
} Expected behaviorBehavior on Linux and Windows must be identical. Actual behaviorOn Windows, it is not possible to call Regression?No Known WorkaroundsRecreate socket on client side by the cost of allocation. Configuration.NET 6.0.301 Other informationNo response
|
Triage: Would be nice to understand it and route it to appropriate team (us or Windows). Not high pri -> Future. |
Description
On Linux,
Socket.DisconnectAsync
works fine and allows to reuseSocket
object to connect again. On Windows,DisconnectAsync
completes successfully. However, subsequent call ofConnectAsync
fails withSocketException
andSocketError.IsConnected
error. At the same time,Socket.Connected
property returns false.Reproduction Steps
Expected behavior
Behavior on Linux and Windows must be identical.
Actual behavior
On Windows, it is not possible to call
ConnectAsync
on disconnected socket.Regression?
No
Known Workarounds
Recreate socket on client side by the cost of allocation.
Configuration
.NET 6.0.301
Windows 10 Enterprise 20H2 (Build 1904.1706)
Other information
No response
The text was updated successfully, but these errors were encountered: