-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Allow ConnectionListener.AcceptAsync() to return null #41304
Comments
Tagging subscribers to this area: @dotnet/ncl |
I though we agreed to support returning null |
It's worth pointing out that it's almost always the case that there's an outstanding AcceptAsync when the listener is disposed. In other words, this isn't some corner case, it's the common case, and that's why we want to avoid exceptions here. |
namespace System.Net.Connections
{
public partial class ConnectionListener
{
public abstract ValueTask<Connection?> AcceptAsync(
IConnectionProperties? options = null,
CancellationToken cancellationToken = default);
}
} |
Reopening for 5.0 backport in #41453 |
Co-authored-by: Natalia Kondratyeva <[email protected]> Backport of #41442 to release/5.0 As it was discussed in #41304, with current System.Net.Connections APIs, listeners need to throw from AcceptAsync when shutting down since AcceptAsync cannot return null. This PR allows AcceptAsync to return null, to avoid unnecessary first-chance exceptions when listeners are gracefully shutting down.
Background and Motivation
When migrating Kestrel to the new System.Net.Connections APIs, I noticed that listeners need to throw from AcceptAsync when shutting down since AcceptAsync cannot return null (at least according to the signature).
In the case where there are ongoing AcceptAsync calls when the listener is disposed, I would prefer to be able to return null rather than throw an exception in order to avoid unnecessary first-chance exceptions when listeners are gracefully shutting down. For listeners based on managed Sockets, there's likely to be an exception either way, but other listeners my be able to avoid throwing exceptions during shutdown entirely.
null
should never be returned unless the listener has been closed.null
indicates to accept loops that they should exit.Proposed API
Alternative Designs
Throwing an OperationCanceledException, ObjectDisposedException or similar instead of returning null.
cc @geoffkizer @scalablecory @davidfowl
The text was updated successfully, but these errors were encountered: