Skip to content

Commit 3b23cde

Browse files
committed
review comments
1 parent 693b487 commit 3b23cde

File tree

2 files changed

+39
-41
lines changed

2 files changed

+39
-41
lines changed

error-codes/README.md

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
# Error Codes
22

3+
| Lifecycle Stage | Maturity | Status | Latest Revision |
4+
| --------------- | ------------- | ------ | --------------- |
5+
| 1A | Working Draft | Active | r0, 2023-01-23 |
6+
7+
Authors: [@sukunrt]
8+
9+
Interest Group: [@marcopolo], [@achingbrain]
10+
11+
[@MarcoPolo]: https://github.com/MarcoPolo
12+
[@achingbrain]: https://github.com/achingbrain
13+
314
## Introduction
4-
In the event that a node detects violation of a protocol or is unable to
5-
complete the necessary steps required for the protocol, it's useful to provide a
6-
reason for disconnection to the other end. This error code can be sent on both
7-
Connection Close and Stream Reset. Its purpose is similar to http response
8-
status. A server, on receiving an invalid request can reset the stream providing
9-
a `BAD_REQUEST` error code, when it's busy handling too many requests can
10-
provide a `RATE_LIMITED` error code, etc. An error code doesn't always indicate
11-
an error condition. For example, a connection may be closed prematurely because
12-
a connection to the same peer on a better transport is available.
15+
16+
When closing a connection or resetting a stream, it's useful to provide the peer with a code that explains the reason for the closure. This enables the peer to better respond to the abrupt closures. For instance, it can implement a backoff strategy to retry _only_ when it receives a `RATE_LIMITED` error code. An error code doesn't always indicate an error condition. For example, a connection may be closed because a connection to the same peer on a better transport is available.
1317

1418
## Semantics
15-
Error codes are unsigned 32bit integers. The range 0 to 10000 is reserved for
19+
Error codes are unsigned 32-bit integers. The range 0 to 10000 is reserved for
1620
libp2p errors. Application specific errors can be defined by protocols from
1721
integers outside of this range. Implementations supporting error codes MUST
1822
provide the error code provided by the other end to the application.
1923

20-
Error codes provide a best effort guarantee that the error will be propogated to
21-
the applciation layer. This provides backwards compatibility with older nodes,
22-
allows smaller implementations and using transports that don't provide a
24+
Error codes provide a best effort guarantee that the error will be propagated to
25+
the application layer. This provides backwards compatibility with older nodes,
26+
allows smaller implementations, and using transports that don't provide a
2327
mechanism to provide an error code. For example, Yamux has no equivalent of
2428
QUIC's [STOP_SENDING](https://www.rfc-editor.org/rfc/rfc9000.html#section-3.5-4)
2529
frame that would tell the peer that the node has stopped reading. So there's no
@@ -38,18 +42,17 @@ Close error code on streams that are reset as a result of remote closing the
3842
connection.
3943

4044
For stream resets, when the underlying transport supports it, implementations
41-
SHOULD allow sending an error code on both closing the read side of the stream
42-
and resetting the write side of the stream.
45+
SHOULD allow sending an error code on both closing the read side of the stream, and resetting the write side of the stream.
4346

4447
## Libp2p Error Codes
4548
TODO!
4649

4750
## Wire Encoding
48-
Different transports will encode the 32bit error code differently.
51+
Different transports will encode the 32-bit error code differently.
4952

5053
### QUIC
5154
QUIC provides the ability to send an error on closing the read end of the
52-
stream, reseting the write end of the stream and on closing the connection.
55+
stream, resetting the write end of the stream and on closing the connection.
5356

5457
For stream resets, the error code MUST be sent on the `RESET_STREAM` or the
5558
`STOP_SENDING` frame using the `Application Protocol Error Code` field as per
@@ -64,34 +67,26 @@ using the Error Code field as defined in the
6467
Yamux has no `STOP_SENDING` frame, so there's no way to signal an error on
6568
closing the read side of the stream.
6669

67-
For Connection Close, the 32bit Length field is to be interpreted as the error
68-
code. The error code MUST be sent as an Big Endian unsigned 32 bit integer.
70+
For Connection Close, the 32-bit Length field is interpreted as the error
71+
code.
6972

70-
For Stream Resets, the error code is sent as the first 4 bytes of the Data Frame
71-
following the header with RST flag set as defined in the [yamux spec
73+
For Stream Resets, the error code is sent in the `Window Update` frame, with the 32-bit Length field interpreted as the error code. See [yamux spec
7274
extension](https://github.com/libp2p/specs/pull/622).
7375

74-
Note: On TCP connections with `SO_LINGER` set to 0, the error code on connection
75-
close may not be delivered.
76+
Note: On TCP connections with `SO_LINGER` set to 0, the Connection Close error code may not be delivered.
7677

7778
### WebRTC
78-
Since WebRTC doesn't provide reliable delivery for frames that are followed by
79-
closing of the underlying data channel, there's no simple way to introduce error
80-
codes in the current implementation. Consider the most common use case of
81-
resetting both read and write sides of the stream and closing the data channel.
82-
The chrome implementation will not deliver the final `RESET_STREAM` msg and
83-
while the go implementation will delivery the `RESET_STREAM` frame and then
84-
close the data channel, there's no guarantee that the chrome implementation will
85-
provide the `RESET_STREAM` msg to the application layer after it receives the
86-
data channel close message.
79+
There is no way to provide any information on closing a peer connection in WebRTC. Providing error codes on Connection Close will be taken up in the future.
80+
81+
For Stream Resets, the error code can be sent in the `errorCode` field of the WebRTC message with `flag` set to `RESET_STREAM` .
8782

8883
### WebTransport
89-
Error codes for webtransport will be introduced when browsers upgrade to draft-9
90-
of the spec. The current webtransport spec implemented by chrome and firefox is
91-
[draft-2 of webtransport over
92-
http3](https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-02.html#section-4.3-2).
93-
This version allows for only a 1 byte error code. 1 byte is too restrictive and
94-
as the latest webtransport draft,
95-
(draft-9)[https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-02.html#section-4.3-2]
96-
allows for a 4 byte error code to be sent on stream resets, we will introduce
97-
error codes over webtransport later.
84+
Error codes for WebTransport will be introduced when browsers upgrade to draft-9
85+
of the spec. The current WebTransport spec implemented by Chrome and Firefox is
86+
[draft-2 of WebTransport over
87+
HTTP/3](https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-02.html#section-4.3-2).
88+
This version allows for only a 1-byte error code. 1 byte is too restrictive and
89+
as the latest WebTransport draft,
90+
[draft-9](https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-02.html#section-4.3-2)
91+
allows for a 4-byte error code to be sent on stream resets, we will introduce
92+
error codes over WebTransport later.

webrtc/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ message Message {
7676
optional Flag flag=1;
7777
7878
optional bytes message = 2;
79+
80+
// errorCode is the reason for resetting the stream. This field is only meaningful when flag is set to RESET_STREAM
81+
optional uint32 errorCode = 3;
7982
}
8083
```
8184

0 commit comments

Comments
 (0)