Skip to content

[API Proposal] QuicError.AlpnInUse #74755

Closed

Description

@rzikm

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,
    }
}

Activity

  1. ghost added
    untriaged
    on Aug 29, 2022
  2. added this to the 8.0.0 milestone on Aug 29, 2022
  3. ghost removed
    untriaged
    on Aug 29, 2022
  4. added
    api-ready-for-review
    on Aug 29, 2022
  5. karelz commented on Aug 29, 2022

    @karelz
    Member

    I don't think anyone will push back -- marking as ready for API review. @dotnet/ncl please speak up if you have second thoughts ...

  6. halter73 commented on Sep 6, 2022

    @halter73
    Member

    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 (QuicException ex) 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?

    If the problem is what's described in #73045:

    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?

  7. rzikm commented on Sep 6, 2022

    @rzikm
    MemberAuthor

    What is this error currently reported with?

    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?

  8. halter73 commented on Sep 6, 2022

    @halter73
    Member

    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.

  9. nibanks commented on Sep 6, 2022

    @nibanks

    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.

  10. halter73 commented on Sep 6, 2022

    @halter73
    Member

    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.

  11. nibanks commented on Sep 6, 2022

    @nibanks

    IMHO, most apps fall into the following buckets:

    1. Bind to a protocol specific port. Only that work can be used for the protocol.
    2. 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.

  12. terrajobst commented on Sep 9, 2022

    @terrajobst
    Contributor

    We discussed this over email and concluded that we like the proposal as-is:

    namespace System.Net.Quic;
    
    public partial enum QuicError
    {
        // Existing members omitted
        AlpnInUse
    }
  13. added
    api-approved
    and removed
    api-ready-for-review
    on Sep 9, 2022
  14. ghost added
    in-pr
    on Sep 12, 2022
  15. ghost removed
    in-pr
    on Sep 30, 2022
  16. ghost locked as resolved and limited conversation to collaborators on Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.Net.Quic

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions