<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc version 1.6.36 (Ruby 3.2.2) -->
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-ietf-quic-reliable-stream-reset-01" category="std" consensus="true" tocInclude="true" sortRefs="true" symRefs="true" version="3">
  <!-- xml2rfc v2v3 conversion 3.17.4 -->
  <front>
    <title abbrev="QUIC Reliable Stream Reset">Reliable QUIC Stream Resets</title>
    <seriesInfo name="Internet-Draft" value="draft-ietf-quic-reliable-stream-reset-01"/>
    <author initials="M." surname="Seemann" fullname="Marten Seemann">
      <organization>Protocol Labs</organization>
      <address>
        <email>martenseemann@gmail.com</email>
      </address>
    </author>
    <author fullname="奥一穂" asciiFullname="Kazuho Oku">
      <organization>Fastly</organization>
      <address>
        <email>kazuhooku@gmail.com</email>
      </address>
    </author>
    <date year="2023" month="July" day="04"/>
    <area>Transport</area>
    <workgroup>QUIC</workgroup>
    <keyword>Internet-Draft</keyword>
    <abstract>
      <?line 34?>

<t>QUIC (<xref target="RFC9000"/>) defines a RESET_STREAM frame to reset a stream. When a
sender resets a stream, it stops retransmitting STREAM frames for this stream.
On the receiver side, there is no guarantee that any of the data sent on that
stream is delivered to the application.
This document defines a new QUIC frame, the CLOSE_STREAM frame, that allows
closing and resetting of a stream, while guaranteeing reliable delivery of
stream data up to a certain byte offset.</t>
    </abstract>
    <note removeInRFC="true">
      <name>Discussion Venues</name>
      <t>Discussion of this document takes place on the
    QUIC Working Group mailing list (quic@ietf.org),
    which is archived at <eref target="https://mailarchive.ietf.org/arch/browse/quic/"/>.</t>
      <t>Source for this draft and an issue tracker can be found at
    <eref target="https://github.com/quicwg/draft-ietf-quic-reliable-stream-reset"/>.</t>
    </note>
  </front>
  <middle>
    <?line 44?>

<section anchor="introduction">
      <name>Introduction</name>
      <t>QUIC v1 (<xref target="RFC9000"/>) allows streams to be reset.  When a stream is
reset, the sender doesn't retransmit stream data for the respective stream.
On the receiver side, the QUIC stack is free to surface the stream reset to the
application immediately, even if it has already received stream data for that
stream.</t>
      <t>Applications running on top of QUIC might need to send an identifier at the
beginning of the stream in order to associate that stream with a specific
subpart of the application. For example, WebTransport
(<xref target="WEBTRANSPORT"/>) uses a variable-length-encoded
integer (as defined in QUIC v1) to transmit the ID of the WebTransport session to
the receiver. It is desirable that the receiver is able to associate incoming
streams with their respective subpart of the application, even if the QUIC stream
is reset before the identifier at the beginning of the stream was read.</t>
      <t>Another use-case is relaying data from an external data source. When a relay
is sending data being read from an external source and encounters an error, it
might want to use a stream reset to signal that error, at the same time making
sure that all data being read previously is delivered to the peer.</t>
      <t>This document describes a QUIC extension defining a new frame type, the
CLOSE_STREAM frame. This frame allows an endpoint to mark a portion at
the beginning of the stream which will then be guaranteed to be delivered to
receiver's application, even if the stream was reset.</t>
    </section>
    <section anchor="conventions-and-definitions">
      <name>Conventions and Definitions</name>
      <t>The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL
NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
"<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted as
described in BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when, they
appear in all capitals, as shown here.</t>
      <?line -18?>

</section>
    <section anchor="negotiating-extension-use">
      <name>Negotiating Extension Use</name>
      <t>Endpoints advertise their support of the extension described in this document by
sending the close_stream (0x17f7586d2cb570) transport parameter
(Section 7.4 of <xref target="RFC9000"/>) with an empty value. An implementation that
understands this transport parameter <bcp14>MUST</bcp14> treat the receipt of a non-empty
value as a connection error of type TRANSPORT_PARAMETER_ERROR.</t>
      <t>In order to allow reliable stream resets in 0-RTT packets, the client <bcp14>MUST</bcp14>
remember the value of this transport parameter.  If 0-RTT data is accepted by
the server, the server <bcp14>MUST</bcp14> not disable this extension on the resumed
connection.</t>
    </section>
    <section anchor="closestream-frame">
      <name>CLOSE_STREAM Frame</name>
      <t>Conceptually, the CLOSE_STREAM frame is a RESET_STREAM frame with an
added Reliable Size field.</t>
      <artwork><![CDATA[
CLOSE_STREAM Frame {
  Type (i) = 0x20..0x21,
  Stream ID (i),
  [Application Protocol Error Code (i)],
  Final Size (i),
  Reliable Size (i),
}
]]></artwork>
      <t>The CLOSE_STREAM frames contain the following fields:</t>
      <t>Stream ID:  A variable-length integer encoding of the stream ID of
      the stream being terminated.</t>
      <t>Application Protocol Error Code:  A variable-length integer
    containing the application protocol error code (see Section 20.2)
    that indicates why the stream is being closed. If the Type is 0x20,
    this field is not included.</t>
      <t>Final Size:  A variable-length integer indicating the final size of
    the stream by the RESET_STREAM sender, in units of bytes; see
    (Section 4.5 of <xref target="RFC9000"/>).</t>
      <t>Reliable Size:  A variable-length integer indicating the amount of
    data that needs to be delivered to the application even though
    the stream is reset.</t>
      <t>If the Reliable Size is larger than the Final Size, the receiver <bcp14>MUST</bcp14> close the
connection with a connection error of type FRAME_ENCODING_ERROR.</t>
      <t>CLOSE_STREAM frames are ack-eliciting. When lost, they <bcp14>MUST</bcp14> be retransmitted,
unless the stream state has transitioned to "Data Recvd" or "Reset Recvd" due
to transmission and acknowledgement of other frames (see <xref target="multiple-frames"/>).</t>
    </section>
    <section anchor="closing-streams">
      <name>Closing Streams</name>
      <section anchor="without-an-error">
        <name>Without an Error</name>
        <t>When closing a stream with an error, the node has the choise between a STREAM
frame that carries the FIN bit and a CLOSE_STREAM frame of type 0x20.</t>
        <t>The CLOSE_STREAM frame can be used to reduce the reliable offset after a
STREAM frame with a FIN bit has been sent. If STREAM frames containing data
up to that byte offset are lost, the initiator <bcp14>MUST</bcp14> retransmit this data, as
described in (Section 13.3 of <xref target="RFC9000"/>). Data sent beyond that byte offset
<bcp14>SHOULD NOT</bcp14> be retransmitted.</t>
      </section>
      <section anchor="using-an-error-code">
        <name>Using an Error Code</name>
        <t>When resetting a stream, the node has the choice between using a RESET_STREAM
frame and a CLOSE_STREAM frame of type 0x21. When using a RESET_STREAM frame,
the behavior is unchanged from the behavior described in (<xref target="RFC9000"/>).</t>
        <t>When using the CLOSE_STREAM frame, the initiator <bcp14>MUST</bcp14> guarantee reliable delivery of stream data of at least
Reliable Size bytes.  If STREAM frames containing data up to that byte offset
are lost, the initiator <bcp14>MUST</bcp14> retransmit this data, as described in
(Section 13.3 of <xref target="RFC9000"/>). Data sent beyond that byte offset <bcp14>SHOULD NOT</bcp14> be
retransmitted.</t>
        <t>As described in (Section 3.2 of <xref target="RFC9000"/>), it <bcp14>MAY</bcp14> deliver data beyond that
offset to the application.</t>
      </section>
      <section anchor="multiple-frames">
        <name>Multiple CLOSE_STREAM / RESET_STREAM frames</name>
        <t>The initiator <bcp14>MAY</bcp14> send multiple CLOSE_STREAM frames for the same
stream in order to reduce the Reliable Size.  It <bcp14>MAY</bcp14> also send a RESET_STREAM
frame, which is equivalent to sending a CLOSE_STREAM frame with a
Reliable Size of 0.</t>
        <t>When sending multiple frames for the same stream, the initiator <bcp14>MUST NOT</bcp14> increase
the Reliable Size.  When receiving a CLOSE_STREAM frame with a lower
Reliable Size, the receiver only needs to deliver data up the lower Reliable
Size to the application. It <bcp14>MUST NOT</bcp14> expect the delivery of any data beyond that
byte offset.</t>
        <t>Reordering of packets might lead to a CLOSE_STREAM frame with a higher
Reliable Size being received after a CLOSE_STREAM frame with a lower
Reliable Size.  The receiver <bcp14>MUST</bcp14> ignore any CLOSE_STREAM frame that
increases the Reliable Size.</t>
        <t>When sending another CLOSE_STREAM, RESET_STREAM or STREAM frame carrying a FIN
bit for the same stream, the initiator <bcp14>MUST NOT</bcp14> change the Application Error
Code or the Final Size.  This also means that sending CLOSE_STREAM frames of
different types is not permitted. If the receiver detects a change in those
fields, it <bcp14>MUST</bcp14> close the connection with a connection error of type
STREAM_STATE_ERROR.</t>
      </section>
    </section>
    <section anchor="security-considerations">
      <name>Security Considerations</name>
      <t>TODO Security</t>
    </section>
    <section anchor="iana-considerations">
      <name>IANA Considerations</name>
      <t>This document has no IANA actions.</t>
    </section>
  </middle>
  <back>
    <references>
      <name>Normative References</name>
      <reference anchor="RFC9000">
        <front>
          <title>QUIC: A UDP-Based Multiplexed and Secure Transport</title>
          <author fullname="J. Iyengar" initials="J." role="editor" surname="Iyengar"/>
          <author fullname="M. Thomson" initials="M." role="editor" surname="Thomson"/>
          <date month="May" year="2021"/>
          <abstract>
            <t>This document defines the core of the QUIC transport protocol. QUIC provides applications with flow-controlled streams for structured communication, low-latency connection establishment, and network path migration. QUIC includes security measures that ensure confidentiality, integrity, and availability in a range of deployment circumstances. Accompanying documents describe the integration of TLS for key negotiation, loss detection, and an exemplary congestion control algorithm.</t>
          </abstract>
        </front>
        <seriesInfo name="RFC" value="9000"/>
        <seriesInfo name="DOI" value="10.17487/RFC9000"/>
      </reference>
      <reference anchor="WEBTRANSPORT">
        <front>
          <title>WebTransport over HTTP/3</title>
          <author fullname="Alan Frindell" initials="A." surname="Frindell">
            <organization>Facebook</organization>
          </author>
          <author fullname="Eric Kinnear" initials="E." surname="Kinnear">
            <organization>Apple Inc.</organization>
          </author>
          <author fullname="Victor Vasiliev" initials="V." surname="Vasiliev">
            <organization>Google</organization>
          </author>
          <date day="13" month="June" year="2023"/>
          <abstract>
            <t>   WebTransport [OVERVIEW] is a protocol framework that enables clients
   constrained by the Web security model to communicate with a remote
   server using a secure multiplexed transport.  This document describes
   a WebTransport protocol that is based on HTTP/3 [HTTP3] and provides
   support for unidirectional streams, bidirectional streams and
   datagrams, all multiplexed within the same HTTP/3 connection.

            </t>
          </abstract>
        </front>
        <seriesInfo name="Internet-Draft" value="draft-ietf-webtrans-http3-07"/>
      </reference>
      <reference anchor="RFC2119">
        <front>
          <title>Key words for use in RFCs to Indicate Requirement Levels</title>
          <author fullname="S. Bradner" initials="S." surname="Bradner"/>
          <date month="March" year="1997"/>
          <abstract>
            <t>In many standards track documents several words are used to signify the requirements in the specification. These words are often capitalized. This document defines these words as they should be interpreted in IETF documents. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t>
          </abstract>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="2119"/>
        <seriesInfo name="DOI" value="10.17487/RFC2119"/>
      </reference>
      <reference anchor="RFC8174">
        <front>
          <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
          <author fullname="B. Leiba" initials="B." surname="Leiba"/>
          <date month="May" year="2017"/>
          <abstract>
            <t>RFC 2119 specifies common key words that may be used in protocol specifications. This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the defined special meanings.</t>
          </abstract>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="8174"/>
        <seriesInfo name="DOI" value="10.17487/RFC8174"/>
      </reference>
    </references>
    <?line 212?>

<section numbered="false" anchor="acknowledgments">
      <name>Acknowledgments</name>
      <t>TODO acknowledge.</t>
    </section>
  </back>
  <!-- ##markdown-source:
H4sIAAAAAAAAA6VZzXIbuRG+4ykQ6rB2imQo2Y5tZr0brkTtqiKJDkWXa8vl
UoEzIInSzGAMYETTKrlSeZJc9pA3yDnPklReI90NzHCGHHl3Ex9kEr/98/WH
7mav12NOuUQOeWcqEyXmieR/fnN2zK+ckSLlU2mlsx0m5nMjb2EVTVZL66s6
LNZRJlI4KzZi4XpKukXvQ6Gingnre5bWw3dY3xscskg4udRmM+TWxYyp3Ay5
M4V1R4PBy8ERE7B8yGdGZDbXxrG1NjdLo4t8SFKyG7mBoXjIzzInTQaHnuDV
jFknsvhaJDoDcTbSMpsK464/FNpJO+SZZrka8ndOR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