Repository navigation
Closed
Description
Description
When two listeners are started on the same port, I get a generic error message instead of the address in use.
Note: this is on my local dev machine. I've seen S.N.Q report the right error message, e.g. dotnet/aspnetcore#42967
Reproduction Steps
See the unit test BindAsync_ListenersSharePort_ThrowAddressInUse added in dotnet/aspnetcore#42983
Expected behavior
QuicException has a status of AddressInUse and a friendly error message.
Actual behavior
ListenAsync throws this error: System.Net.Quic.QuicException : An internal error has occurred. ListenerStart failed: QUIC_STATUS_INVALID_STATE
Someone who gets that error message will have no idea what the problem is or how to fix it.
Full logs:
Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests.QuicConnectionListenerTests.BindAsync_AddressInUse_Log
Source: QuicConnectionListenerTests.cs line 149
Duration: 63 ms
Message:
System.Net.Quic.QuicException : An internal error has occurred. ListenerStart failed: QUIC_STATUS_INVALID_STATE
Stack Trace:
ThrowHelper.ThrowIfMsQuicError(Int32 status, String message)
QuicListener.ctor(QuicListenerOptions options)
QuicListener.ListenAsync(QuicListenerOptions options, CancellationToken cancellationToken)
QuicConnectionListener.CreateListenerAsync() line 122
QuicTransportFactory.BindAsync(EndPoint endpoint, IFeatureCollection features, CancellationToken cancellationToken) line 64
QuicTestHelpers.CreateConnectionListenerFactory(ILoggerFactory loggerFactory, ISystemClock systemClock, Boolean clientCertificateRequired, Int64 defaultCloseErrorCode, Int32 port) line 63
QuicConnectionListenerTests.BindAsync_AddressInUse_Log() line 156
QuicConnectionListenerTests.BindAsync_AddressInUse_Log() line 156
--- End of stack trace from previous location ---
Standard Output:
| [0.006s] TestLifetime Information: Starting test BindAsync_AddressInUse_Log at 2022-07-29T04:39:45
| [0.038s] Microsoft.AspNetCore.Server.Kestrel.Transport.Quic Debug: QUIC listener starting with configured endpoint 127.0.0.1:0.
| [0.062s] Microsoft.AspNetCore.Server.Kestrel.Transport.Quic Debug: QUIC listener starting with configured endpoint 127.0.0.1:65152.
| [0.072s] Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests.QuicConnectionListenerTests Error: Test threw an exception.
| System.Net.Quic.QuicException: An internal error has occurred. ListenerStart failed: QUIC_STATUS_INVALID_STATE
| at System.Net.Quic.ThrowHelper.ThrowIfMsQuicError(Int32 status, String message)
| at System.Net.Quic.QuicListener..ctor(QuicListenerOptions options)
| at System.Net.Quic.QuicListener.ListenAsync(QuicListenerOptions options, CancellationToken cancellationToken)
| at Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal.QuicConnectionListener.CreateListenerAsync() in C:\Development\Source\aspnetcore\src\Servers\Kestrel\Transport.Quic\src\Internal\QuicConnectionListener.cs:line 122
| at Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.QuicTransportFactory.BindAsync(EndPoint endpoint, IFeatureCollection features, CancellationToken cancellationToken) in C:\Development\Source\aspnetcore\src\Servers\Kestrel\Transport.Quic\src\QuicTransportFactory.cs:line 64
| at Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests.QuicTestHelpers.CreateConnectionListenerFactory(ILoggerFactory loggerFactory, ISystemClock systemClock, Boolean clientCertificateRequired, Int64 defaultCloseErrorCode, Int32 port) in C:\Development\Source\aspnetcore\src\Servers\Kestrel\Transport.Quic\test\QuicTestHelpers.cs:line 63
| at Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests.QuicConnectionListenerTests.BindAsync_AddressInUse_Log() in C:\Development\Source\aspnetcore\src\Servers\Kestrel\Transport.Quic\test\QuicConnectionListenerTests.cs:line 156
| at Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests.QuicConnectionListenerTests.BindAsync_AddressInUse_Log() in C:\Development\Source\aspnetcore\src\Servers\Kestrel\Transport.Quic\test\QuicConnectionListenerTests.cs:line 156
| at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 264
| --- End of stack trace from previous location ---
| at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\ExecutionTimer.cs:line 48
| at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in C:\Dev\xunit\xunit\src\xunit.core\Sdk\ExceptionAggregator.cs:line 90
| [0.074s] TestLifetime Information: Finished test BindAsync_AddressInUse_Log in 0.0711134s
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Activity
rzikm commentedon Jul 29, 2022
The error originates from MsQuic from here:
https://github.com/microsoft/msquic/blob/main/src/core/listener.c#L338
We should probably check with MsQuic team.
JamesNK commentedon Jul 29, 2022
BindAsync_ListenersSharePort_ThrowAddressInUsefailing on build server: https://dev.azure.com/dnceng/public/_build/results?buildId=1910981&view=ms.vss-test-web.build-test-results-tab&runId=49596722&resultId=109366&paneView=debugrzikm commentedon Jul 29, 2022
The issue seems to be only in cases where you try to start two QUIC listeners on the same port with intersecting ALPN sets inside the same process. When the desired port is occupied by a different process or by a
Socketinstance, the call throws withQuicError.AddressInUseas expected.The problem with two QuicListeners in the same process is that MsQuic allows binding two listeners on the same port as long as they don't have conflicting ALPNs, so returning
AddressInUsemight be confusing because creating the listener with different ALPN would succeed.From a brief conversation with MsQuic team, some possible solutions are:
JamesNK commentedon Jul 29, 2022
Adding
QuicError.AlpnInUseto S.N.Q sounds the best. It would be nice if the exception message says which ALPN is in use, but it's not critical.In Kestrel, we'll probably still surface the error to the user that the port is already in use. With HTTP/3, the ALPN is always
h3.karelz commentedon Aug 2, 2022
Triage: Limited to corner-case scenario - 2 QuicListener using the same port in the same process. Moving to Future.
JamesNK commentedon Aug 2, 2022
When is the decision about future issues going into .NET 8?
I agree it's not common, but people do all kinds of crazy stuff in server apps. Having a clear error message when they mess this up would stop those people from getting stuck with an unhelpful error message.
wfurt commentedon Aug 2, 2022
Since it seems like there is no distinct error, we would need MsQuic changes to detect this reliably.
cc: @nibanks for more thoughts.
nibanks commentedon Aug 3, 2022
I've got a PR written up that changes the return value to (a newly defined)
QUIC_STATUS_ALPN_IN_USE. But a problem I have with this is that it's an API behavior change. Strictly speaking, it's breaking, but I'm wondering if I can slip it through unnoticed.microsoft/msquic#2936
karelz commentedon Aug 3, 2022
@JamesNK to answer your earlier question -- we will start thinking systematically about 8.0 vs. Future in October the earliest.