From acef46194e92dafca8c11ecfaf20aca8631e4aa3 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 16 Jun 2021 08:47:28 +0200 Subject: [PATCH] Elaborate on obtaining a connection In particular, define resolving domains and allow connection creation to be a race. As a result this also inlines some of the time capture moments to be directly inside the obtain a connection algorithm. This helps with #1243. --- fetch.bs | 195 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 124 insertions(+), 71 deletions(-) diff --git a/fetch.bs b/fetch.bs index bfcf4df4a..be6ae52b9 100644 --- a/fetch.bs +++ b/fetch.bs @@ -2204,6 +2204,47 @@ unset or keepalive is false, termi fetch record's fetch. +

Resolving domains

+ +

To resolve a domain, given a network partition key +key and a domain domain, perform an implementation-defined +operation to turn domain into a set of one or more +IP addresses. If this operation succeeds, return the set of +IP addresses. If it fails, return failure. The results of this operation may be cached. +If they are cached, key should be used as part of the cache key. + +

+

Typically this operation would involve DNS and as such caching can happen on DNS servers without + key being taken into account. Depending on the implementation it might also not be + possible to take key into account locally. [[RFC1035]] + +

The order of the IP addresses resolve a domain can return return can differ + between invocations. + +

The particulars (apart from the cache key) are not tied down as they are not pertinent to the + system the Fetch Standard establishes. Other documents ought not to build on this primitive without + having a considered discussion with the Fetch Standard community first. +

+ +

To resolve an origin, given a network partition key key and an +origin origin: + + +

    +
  1. If origin's host is an IP address, then return + « origin's host ». + +

  2. If the user agent is configured to use a proxy that resolves domains on its own, then return + « origin's host ». + +

  3. Return the result of running resolve a domain given key and + origin's host. +

+ +

The same caveat applies. Do not build on this without having a considered discussion +with the Fetch Standard community first. + +

Connections

A user agent has an associated connection pool. A @@ -2274,7 +2315,7 @@ steps:


To obtain a connection, given a -network partition key key, origin, origin, boolean +network partition key key, origin origin, boolean credentials, an optional boolean forceNew (default false), an optional boolean http3Only (default false), and an optional boolean dedicated (default false), run these @@ -2298,40 +2339,33 @@ steps: connection. -

  • Let connection be null. +

  • Let timingInfo be a new connection timing info. -

  • -

    Run these steps, but abort when the ongoing fetch is terminated: +

  • Set timingInfo's domain lookup start time to + the unsafe shared current time. -

      -
    1. -

      Set connection to a new connection whose key is - key, origin is origin, and - credentials is credentials. - Record connection timing info given connection and use - connection to establish an HTTP connection to origin. - [[!HTTP]] [[!HTTP-SEMANTICS]] [[!HTTP-COND]] [[!HTTP-CACHING]] [[!HTTP-AUTH]] [[!TLS]] - -

      If http3Only is true, then establish an HTTP/3 connection. [[!HTTP3]] +

    2. Let hosts be the result of running resolve an origin given key + and origin. -

      When establishing an HTTP/3 connection, include SETTINGS_ENABLE_WEBTRANSPORT with a value of - 1 and H3_DATAGRAM with a value of 1 in the initial SETTINGS frame. [[!WEBTRANSPORT-HTTP3]] - [[!HTTP3-DATAGRAM]] +

    3. If hosts is failure, then return failure. -

      If credentials is false, then do not send a TLS client certificate. - -

      If establishing a connection does not succeed (e.g., a DNS, TCP, or TLS error), then return - failure. -

    +
  • Set timingInfo's domain lookup end time to + the unsafe shared current time.

  • -

    If aborted, then: +

    Let connection be the result of running this step: run create a connection + given key, origin, credentials, an implementation-defined + host from hosts, timingInfo, and http3Only an + implementation-defined number of times, in parallel from each other, and wait for at + least 1 to return a value. In an implementation-defined manner, select a value to return + from the returned values and return it. Any other returned values that are connections may + be closed. -

      -
    1. If connection is not null, then close connection. +

      Essentially this allows an implementation to pick one or more + IP addresses from the return value of resolve a domain (assuming no proxy) and + race them against each other, favor IPv6 addresses, retry in case of a timeout, etc. -

    2. Return failure. -

    +
  • If connection is failure, then return failure.

  • If dedicated is false, then append connection to the user agent's connection pool. @@ -2339,14 +2373,69 @@ steps:

  • Return connection. -

    This is intentionally a little vague as the finer points are still -evolving. Describing this helps explain the <link rel=preconnect> feature and -clearly stipulates that connections are keyed on -credentials. The latter clarifies that e.g., TLS session identifiers are not reused across -connections whose credentials are false with -connections whose credentials are true. - +

    This is intentionally a little vague as there are a lot of nuances to connection +management that are best left to the discretion of implementers. Describing this helps explain the +<link rel=preconnect> feature and clearly stipulates that connections are +keyed on credentials. The latter clarifies that, e.g., TLS session identifiers are not +reused across connections whose credentials are false with +connections whose credentials are true. + +


    + +

    To create a connection, given a network partition key key, +origin origin, boolean credentials, host +host, connection timing info timingInfo, and boolean +http3Only, run these steps: + +

      +
    1. Set timingInfo's connection start time to the + unsafe shared current time. + +

    2. +

      Let connection be a new connection whose key is + key, origin is origin, + credentials is credentials, and timing info + is timingInfo. Record connection timing info given connection + and use connection to establish an HTTP connection to host, taking + origin into account. [[!HTTP]] [[!HTTP-SEMANTICS]] [[!HTTP-COND]] [[!HTTP-CACHING]] + [[!HTTP-AUTH]] [[!TLS]] + +

      If http3Only is true, then establish an HTTP/3 connection. [[!HTTP3]] + +

      When establishing an HTTP/3 connection, include SETTINGS_ENABLE_WEBTRANSPORT with a value of 1 + and H3_DATAGRAM with a value of 1 in the initial SETTINGS frame. [[!WEBTRANSPORT-HTTP3]] + [[!HTTP3-DATAGRAM]] + +

      If credentials is false, then do not send a TLS client certificate. + +

      If establishing a connection does not succeed (e.g., a TCP or TLS error), then return failure. + +

    3. +

      Set timingInfo's ALPN negotiated protocol to + connection's ALPN Protocol ID, with the following caveats: [[RFC7301]] + +

        +
      • When a proxy is configured, if a tunnel connection is established then this must be the + ALPN Protocol ID of the tunneled protocol, otherwise it must be the ALPN Protocol ID of the first + hop to the proxy. + +

      • +

        In case the user agent is using an experimental, non-registered protocol, the user agent must + use the used ALPN Protocol ID, if any. If ALPN was not used for protocol negotiations, the user + agent may use another descriptive string. + +

        timingInfo's + ALPN negotiated protocol is intended to identify the network + protocol in use regardless of how it was actually negotiated; that is, even if ALPN is not used + to negotiate the network protocol, this is the ALPN Protocol IDs that indicates the protocol in + use. +

      + +

      IANA maintains a + list of ALPN Protocol IDs. + +

    4. Return connection. +


    @@ -2355,18 +2444,6 @@ clearly stipulates that connections are keyed on timing info and observe these requirements:

    The clamp and coarsen connection timing info algorithm ensures that