-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
WaitForConnectionAsync does not respond to cancellation #40289
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Played with this a bit more today and even if this is a doc bug there still seems to be a bit of a problem here because there is no reliable way to break a Given the current implementation of
The second issue can be demonstrated with the following repro: using System;
using System.IO;
using System.IO.Pipes;
using System.Threading.Tasks;
using System.Text;
class Program
{
static async Task Main(string[] args)
{
await RunRepro($"example-pipe");
}
static async Task RunRepro(string pipeName)
{
var server1 = CreateServer();
var server1Task = RunServer(server1);
using var client1 = new NamedPipeClientStream(pipeName);
await client1.ConnectAsync();
await server1Task;
Console.WriteLine("After await server1Task");
var server2 = CreateServer();
var server2Task = RunServer(server2);
server2.Dispose();
// Uncomment this line and the await below will complete
// server1.Dispose();
// This will hang indefinitely because even disposing server2 is not enough
// to break it out of the WaitForConnectionAsync method
await server2Task;
Console.WriteLine("After await server2Task");
async Task RunServer(NamedPipeServerStream server)
{
try
{
await server.WaitForConnectionAsync();
}
catch
{
Console.WriteLine("Error waiting for connection");
}
}
NamedPipeServerStream CreateServer() => new NamedPipeServerStream(
pipeName,
PipeDirection.InOut,
maxNumberOfServerInstances: NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous | PipeOptions.WriteThrough);
}
} This is a bit of a problem because it means once you enter Am I missing a better way to fore the |
@scalablecory, do we expose any way to cancel an asynchronous socket accept operation other than disposing of the socket? |
(Fixing this correctly will likely require the AcceptAsync overload approved-but-not-yet-implemented in #33418.) |
Nope, we need a new API for that. |
These were not implemented. Not sure why they're listed as such. @scalablecory, @geoffkizer |
Copy-paste error. I've fixed it. Note these APIs are (and were) still listed in the initial section containing APIs that need implementing. |
The documentation for
NamedPipeServerStream.WaitForConnectionAsync(CancellationToken)
claims the following:This does not appear to be true though when .NET Core is run in Unix environments. The following code snippet will hang waiting for the
WaitForConnectionAsync
method to complete on Unix. It does not seem to respect the cancellation request. The same code running on Windows though will properly cancel theWaitForConnectionAsync
.Looking at the
WaitForConnectionAsync
implementation on Unix it seems that the cancellation is simply not considered after a quick check at the start of the method.Is the documentation simply out of date here and should be using and not or?
The text was updated successfully, but these errors were encountered: