Skip to content

Raise severity of Kestrel's unexpected transport error logs #29322

Open
@halter73

Description

@halter73

Arbitrary exceptions thrown from SocketConnection's receive and send loops are currently logged at the debug level.

catch (Exception ex)
{
// This is unexpected.
error = ex;
_trace.ConnectionError(ConnectionId, error);
}

private static readonly Action<ILogger, string, Exception?> _connectionError =
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(14, nameof(ConnectionError)), @"Connection id ""{ConnectionId}"" communication error.");

This was done so app developers aren't spammed with useless warnings, but really it just shows the lack of confidence that we properly handle every Exception on every platform.

This might have been prudent when Kestrel's Socket transport was also distributed as a NuGet package meaning we didn't have complete control over what implementation of System.Net.Sockets we might be running on, but that's no longer the case. We should make sure we understand every exception that can be thrown, and catch their specific types.

It's fine leaving the catch (Exception ex) block, but it should log a warning similar to what we do in Kestrel's HttpProtocol class.

catch (Exception ex)
{
Log.LogWarning(0, ex, CoreStrings.RequestProcessingEndError);
}

I think we should change this ASAP so we get feedback on previews. We should also verify that these unexpected connection error debug logs don't currently show up our functional tests.

I think we should do the same thing for unexpected errors in the QUIC transport.

private static readonly Action<ILogger, string, Exception?> _connectionError =
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(3, "ConnectionError"), @"Connection id ""{ConnectionId}"" unexpected error.");
private static readonly Action<ILogger, string, Exception?> _streamError =
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(4, "StreamError"), @"Stream id ""{ConnectionId}"" unexpected error.");

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsfeature-kestrelreliabilityIssues affecting reliability (crashes, memory leaks, stress issues)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions