Consider adding a telemetry event for failed HTTP connection attempts
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- backend, networking, observability
Research direction
Start by reading the connection-failure paths in HttpConnectionPool.Http1.cs, HttpConnectionPool.Http2.cs, and HttpConnectionPool.Http3.cs at the referenced lines, then inspect the System.Net.Http EventSource implementation. The work is done when the telemetry design and coverage for connection-establishment failures are agreed and implemented across the relevant protocol paths.
Written by the indexing model from the issue text.
Description
With how requests are split from connections in SocketsHttpHandler, the user may not always see the errors that occurred during connection establishment (dns + tcp + tls + http/2 handshake).
The errors may be swallowed if we already served the initiating request with a different connection, or if that request timed out.
There are therefore situations where you may have poor visibility into what's happening.
One way of gaining the info is to inject a custom ConnectCallback along the lines of
handler.ConnectCallback = async (context, ct) =>
{
var stopwatch = Stopwatch.StartNew();
var socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
try
{
await socket.ConnectAsync(context.DnsEndPoint, ct);
return new NetworkStream(socket, ownsSocket: true);
}
catch (Exception ex)
{
socket.Dispose();
Console.WriteLine($"Failed to connect to {context.DnsEndPoint} after {stopwatch.ElapsedMilliseconds:N2}: {ex}");
throw;
}
};
This gives you visibility into failures when trying to connect, but not into TLS failures/timeouts.
It's possible to also perform the TLS handshake in the callback, but we don't always make it trivial (how do you pick the host, how do you handle ALPN, potential custom ssl settings, ...).
It seems rather simple for us to add an EventSource event to System.Net.Http that just logs all such failures, corresponding to
https://github.com/dotnet/runtime/blob/05fa8813a7774890b46e60109d8cd6d4c853a014/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http1.cs#L307-L309
https://github.com/dotnet/runtime/blob/05fa8813a7774890b46e60109d8cd6d4c853a014/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http2.cs#L271-L273
https://github.com/dotnet/runtime/blob/05fa8813a7774890b46e60109d8cd6d4c853a014/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http3.cs#L325-L329
Maybe something like
[Event(42, Level = EventLevel.Error)]
public void ConnectionFailed(byte versionMajor, byte versionMinor, string scheme, string host, int port, string? remoteAddress, double elapsedMilliseconds, string exception);
Does this seem reasonable @antonfirsov, maybe we have better ways of exposing such data now?
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·