You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current implementation of QuicListener (backed by MsQuic) allows starting multiple listeners in the same process on the same machine port (each listener listening for connections with different ALPNs). When attempting to start a second listener with the same ALPN (e.g. second HTTP3 listener), we reported an exception with an internal error which caused some confusion among the users (see #73045).
This type of error does not fall in any of the existing QuicError members used to communicate the reason behind a QuicException. The proposed solution is to add a new member AlpnInUse to cover this error case.
public enum QuicError
{
// existing members elided
+ /// <summary>+ /// Another QUIC listener is already listening on one of the requested application protocols on the same port.+ /// </summary>+ AlpnInUse,
}
}
Reacted by Marie Píchová, Karel Zikmund and Ahmet Ibrahim Aksoy
What is this error currently reported with? QuicError.AddressInUse? That's what I'd expect.
Wouldn't it be weird for the following not to retry just because I specified an ALPN protocol while binding?
try{// Bind to a random port with a non-random ALPN protocol}catch(QuicExceptionex)when(ex.QuicError==QuicError.AddressInUse){// Retry binding with a new random port for testing or whatever.}
Do we just stop ever using QuicError.AddressInUse when you're binding with ALPN in the same process?
ListenAsync throws this error: System.Net.Quic.QuicException : An internal error has occurred. ListenerStart failed: QUIC_STATUS_INVALID_STATE
And.
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 Socket instance, the call throws with QuicError.AddressInUse as expected.
That can easily be fixed by using QuicError.AddressInUse and having the exception message indicate that both the address and ALPN protocol are the same and if either one of them were different there would be no conflict (at least between other callers to msquic in the same process). This would be more consistent with errors thrown for other process. And it would be weird to change to protocol to avoid the conflict anyway. The server typically just supports the protocols it supports. The ALPN protocol probably has nothing to do with the likely root cause of the QuicException which is that the address is in use.
@nibanks@rzikm@JamesNK Why are we not just using QUIC_STATUS_ADDRESS_IN_USE in msquic for this? Why did this require adding QUIC_STATUS_ALPN_IN_USE?
It used to be QUIC_STATUS_INVALID_STATE I think, but MsQuic changed it on our behalf (added QUIC_STATUS_ALPN_IN_USE). Now System.Net.Quic throws QuicException with QuicError.InternalError.
Wouldn't it be weird for the following not to retry just because I specified an ALPN protocol while binding?
This will only occur if you explicitly specify the port, i.e. if you explicitly try to listen on a port that an existing QuicListener in the process is listening. If you don't specify a port, then I assume MsQuic will open a new random port (like sockets usually do)
That can easily be fixed by using QuicError.AddressInUse and having the exception message indicate that both the address and ALPN protocol are the same and if either one of them were different there would be no conflict. [...]
Why are we not just using QUIC_STATUS_ADDRESS_IN_USE in msquic for this? Why did this require adding QUIC_STATUS_ALPN_IN_USE?
That is a solution we can consider on the System.Net.Quic level. We usually avoid reporting a different error than MsQuic reports to us, but in this case it might work okay if we make the error message descriptive enough. We would lose the ability to programmatically distinguish between the two error cases, but I am not sure there is a situation we would care. Thoughts? @wfurt, @CarnaViire, @ManickaP?
That is a solution we can consider on the System.Net.Quic level. We usually avoid reporting a different error than MsQuic reports to us, but in this case it might work okay if we make the error message descriptive enough. We would lose the ability to programmatically distinguish between the two error cases, but I am not sure there is a situation we would care. Thoughts? @wfurt, @CarnaViire, @ManickaP?
I see System.Net.Quic as a thin wrapper around msquic, so I agree we should avoid reporting a different error if possible.
That's why I cc'd @nibanks. Does msquic really need to provide a new status for this? I'm not sure why you need to programmatically distinguish these error cases. It only happens if there's an in-process conflict, right? App developers can synchronize and avoid these altogether if they really need to. In most cases, I think app developers would want to handle it like any other QUIC_STATUS_ADDRESS_IN_USE.
I do think it's worth distinguishing the error conditions, because there is another aspect. If you're in the same process, then MsQuic can multiplex different apps, so you would get AlpnInUse. If you're in different processes, then you'll get AddressInUse because another process has the UDP port already.
I understand that in theory you could listen on the same address using a different protocol to avoid the conflict if you're in the same process. I do not think that's worth a separate status.
I think this will likely lead to more bugs in code that assumes catch (QuicException ex) when (ex.QuicError == QuicError.AddressInUse) is sufficient to catch all address conflicts. And what code is going to check for AlpnInUse? What's it going to do? Listen using a different protocol??
Being able to avoid the conflict if you're in the same process by using a different protocol is a nice feature that should be documented, but it does not deserve its own status code. AddressInUse is fine. It is in use. Implying that it's not by using a new status code is misleading. This feedback applies to both AlpnInUse.AlpnInUse and QUIC_STATUS_ALPN_IN_USE.
Bind to a protocol specific port. Only that work can be used for the protocol.
Don't care. Let the stack pick.
In case (1) both AlpnInUse and AddressInUse are fatal errors. There is nothing else to do. No point in retry with the general assumption the current own is likely still going to be using it. In case (2) the errors won't occur because you're pretty much guaranteed to succeed (so long as there isn't a bug somewhere).
So, for (1) I don't really think it matters a whole lot if there is one error or two, but I prefer to err on the side of extra information. If you really do have an edge case where you want to retry, I think it perfectly fine to retry on both error codes. But since it's such a small exception, I don't think it unreasonable to expect exceptional logic for checking 2 error codes instead of 1.
Activity
karelz commentedon Aug 29, 2022
I don't think anyone will push back -- marking as ready for API review. @dotnet/ncl please speak up if you have second thoughts ...
halter73 commentedon Sep 6, 2022
What is this error currently reported with?
QuicError.AddressInUse? That's what I'd expect.Wouldn't it be weird for the following not to retry just because I specified an ALPN protocol while binding?
Do we just stop ever using
QuicError.AddressInUsewhen you're binding with ALPN in the same process?If the problem is what's described in #73045:
And.
That can easily be fixed by using
QuicError.AddressInUseand having the exception message indicate that both the address and ALPN protocol are the same and if either one of them were different there would be no conflict (at least between other callers to msquic in the same process). This would be more consistent with errors thrown for other process. And it would be weird to change to protocol to avoid the conflict anyway. The server typically just supports the protocols it supports. The ALPN protocol probably has nothing to do with the likely root cause of theQuicExceptionwhich is that the address is in use.@nibanks @rzikm @JamesNK Why are we not just using
QUIC_STATUS_ADDRESS_IN_USEin msquic for this? Why did this require addingQUIC_STATUS_ALPN_IN_USE?rzikm commentedon Sep 6, 2022
It used to be QUIC_STATUS_INVALID_STATE I think, but MsQuic changed it on our behalf (added QUIC_STATUS_ALPN_IN_USE). Now System.Net.Quic throws QuicException with QuicError.InternalError.
This will only occur if you explicitly specify the port, i.e. if you explicitly try to listen on a port that an existing QuicListener in the process is listening. If you don't specify a port, then I assume MsQuic will open a new random port (like sockets usually do)
That is a solution we can consider on the System.Net.Quic level. We usually avoid reporting a different error than MsQuic reports to us, but in this case it might work okay if we make the error message descriptive enough. We would lose the ability to programmatically distinguish between the two error cases, but I am not sure there is a situation we would care. Thoughts? @wfurt, @CarnaViire, @ManickaP?
halter73 commentedon Sep 6, 2022
I see System.Net.Quic as a thin wrapper around msquic, so I agree we should avoid reporting a different error if possible.
That's why I cc'd @nibanks. Does msquic really need to provide a new status for this? I'm not sure why you need to programmatically distinguish these error cases. It only happens if there's an in-process conflict, right? App developers can synchronize and avoid these altogether if they really need to. In most cases, I think app developers would want to handle it like any other
QUIC_STATUS_ADDRESS_IN_USE.nibanks commentedon Sep 6, 2022
I do think it's worth distinguishing the error conditions, because there is another aspect. If you're in the same process, then MsQuic can multiplex different apps, so you would get
AlpnInUse. If you're in different processes, then you'll getAddressInUsebecause another process has the UDP port already.halter73 commentedon Sep 6, 2022
I understand that in theory you could listen on the same address using a different protocol to avoid the conflict if you're in the same process. I do not think that's worth a separate status.
I think this will likely lead to more bugs in code that assumes
catch (QuicException ex) when (ex.QuicError == QuicError.AddressInUse)is sufficient to catch all address conflicts. And what code is going to check forAlpnInUse? What's it going to do? Listen using a different protocol??Being able to avoid the conflict if you're in the same process by using a different protocol is a nice feature that should be documented, but it does not deserve its own status code.
AddressInUseis fine. It is in use. Implying that it's not by using a new status code is misleading. This feedback applies to bothAlpnInUse.AlpnInUseandQUIC_STATUS_ALPN_IN_USE.nibanks commentedon Sep 6, 2022
IMHO, most apps fall into the following buckets:
In case (1) both
AlpnInUseandAddressInUseare fatal errors. There is nothing else to do. No point in retry with the general assumption the current own is likely still going to be using it. In case (2) the errors won't occur because you're pretty much guaranteed to succeed (so long as there isn't a bug somewhere).So, for (1) I don't really think it matters a whole lot if there is one error or two, but I prefer to err on the side of extra information. If you really do have an edge case where you want to retry, I think it perfectly fine to retry on both error codes. But since it's such a small exception, I don't think it unreasonable to expect exceptional logic for checking 2 error codes instead of 1.
terrajobst commentedon Sep 9, 2022
We discussed this over email and concluded that we like the proposal as-is: