The Kestrel connection accept loop in ConnectionDispatcher<T> wraps the entire while(true) loop in a single try/catch. If any exception is thrown inside the loop body — including from ILogger calls — the accept loop exits permanently. The process remains alive but never accepts another connection.
The ConnectionDispatcher.cs source even has a comment acknowledging this
A transient failure in logging (or other non-critical operations inside the accept loop) should not permanently kill the connection listener. The accept loop should either:
- Wrap per-iteration work in its own
try/catch so transient failures don't exit the loop, OR
- Implement retry logic with backoff before giving up, OR
- Trigger a graceful server shutdown instead of silently hanging
A sample stack trace:
[CRIT] [Microsoft.AspNetCore.Server.Kestrel] The connection listener failed to accept any new connections.
System.AggregateException: An error occurred while writing to logger(s). (Access is denied.)
---> System.ComponentModel.Win32Exception (5): Access is denied.
at System.Diagnostics.EventLogInternal.InternalWriteEvent(UInt32 eventID, UInt16 category, EventLogEntryType type, String[] strings, Byte[] rawData, String currentMachineName)
at System.Diagnostics.EventLogInternal.WriteEvent(EventInstance instance, Byte[] data, Object[] values)
at Microsoft.Extensions.Logging.EventLog.WindowsEventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category)
at Microsoft.Extensions.Logging.EventLog.EventLogLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func3 formatter) at Microsoft.Extensions.Logging.Logger.<Log>g__LoggerLog|14_0[TState](LogLevel logLevel, EventId eventId, ILogger logger, Exception exception, Func3 formatter, List1& exceptions, TState& state) --- End of inner exception stack trace --- at Microsoft.Extensions.Logging.Logger.ThrowLoggingError(List1 exceptions)
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func3 formatter) at Microsoft.Extensions.Logging.LoggerMessage.<>c__DisplayClass10_01.g__Log|0(ILogger logger, T1 arg1, Exception exception)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ConnectionDispatcher`1.<>c__DisplayClass10_0.<g__AcceptConnectionsAsync|0>d.MoveNext()
- Process stays alive with normal CPU/memory — no crash, no restart
- Port shows
LISTENING in netstat
- The
CRIT log entry "The connection listener failed to accept any new connections" appears exactly once
This is a silent, permanent failure that is extremely difficult to diagnose:
- No process crash → no automatic restart by the host (Service Fabric, IIS, etc.)
The Kestrel connection accept loop in
ConnectionDispatcher<T>wraps the entirewhile(true)loop in a singletry/catch. If any exception is thrown inside the loop body — including fromILoggercalls — the accept loop exits permanently. The process remains alive but never accepts another connection.The
ConnectionDispatcher.cssource even has a comment acknowledging thisA transient failure in logging (or other non-critical operations inside the accept loop) should not permanently kill the connection listener. The accept loop should either:
try/catchso transient failures don't exit the loop, ORA sample stack trace:
[CRIT] [Microsoft.AspNetCore.Server.Kestrel] The connection listener failed to accept any new connections.
System.AggregateException: An error occurred while writing to logger(s). (Access is denied.)
---> System.ComponentModel.Win32Exception (5): Access is denied.
at System.Diagnostics.EventLogInternal.InternalWriteEvent(UInt32 eventID, UInt16 category, EventLogEntryType type, String[] strings, Byte[] rawData, String currentMachineName)
at System.Diagnostics.EventLogInternal.WriteEvent(EventInstance instance, Byte[] data, Object[] values)
at Microsoft.Extensions.Logging.EventLog.WindowsEventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category)
at Microsoft.Extensions.Logging.EventLog.EventLogLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func
3 formatter) at Microsoft.Extensions.Logging.Logger.<Log>g__LoggerLog|14_0[TState](LogLevel logLevel, EventId eventId, ILogger logger, Exception exception, Func3 formatter, List1& exceptions, TState& state) --- End of inner exception stack trace --- at Microsoft.Extensions.Logging.Logger.ThrowLoggingError(List1 exceptions)at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func
3 formatter) at Microsoft.Extensions.Logging.LoggerMessage.<>c__DisplayClass10_01.g__Log|0(ILogger logger, T1 arg1, Exception exception)at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ConnectionDispatcher`1.<>c__DisplayClass10_0.<g__AcceptConnectionsAsync|0>d.MoveNext()
LISTENINGinnetstatCRITlog entry"The connection listener failed to accept any new connections"appears exactly onceThis is a silent, permanent failure that is extremely difficult to diagnose: