Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More complex error codes logic for closing WebSocketConnections/WebSocketStreams #4

Closed
2 tasks done
tegefaulkes opened this issue Apr 6, 2023 · 3 comments
Closed
2 tasks done
Assignees
Labels
development Standard development r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management

Comments

@tegefaulkes
Copy link
Contributor

tegefaulkes commented Apr 6, 2023

Specification

WebSocket/WebSocketConnection

Similarly to QUIC, when we close a WebSocket we can provide a code and message. When closing during normal operation we provide a code of 1000 to imply normal closing.

The Node ws library allows us to provide a type of Buffer or string for the reason. However, the spec states that it must be a utf-8 encoded string, and the browser WebSocket class will only accept a string as a valid reason for .close(code, reason).

Error Codes

The WebSocket instance or may not use the predefined IANA defined close codes when closing a connection based on an error of some sort. We will be using these codes in the 1000-1999 space to define our errors.

IANA gives applications the space of 4000 - 4999 for error codes, these will be what we recommend to the user for stopping a WebSocketConnection.

WebSocketStream

Similarly to QUIC the WebSocketStream spec defined in #2 only has error codes, with all application level errors produced by the user of the API converted with the injected codeToReason and reasonToCode functions.

To note is that the ReadableStream and the WritableStream can be closed independently. When calling .error on a WebStream, a message should be sent to the peer with a shutdown byte that represents whether the ReadableStream or the WritableStream of the peer should be given the error

enum StreamShutdown {
  Read = 0,
  Write = 1,
}
Error Codes

These are the following non-application errors:

const enum StreamErrorCode {
  Unknown = 0,
  // an error parsing the structure of the message
  ErrorReadableStreamParse = 1,
  // an error occurring from the buffer of a readablestream going over the maximum size
  ErrorReadableStreamBufferOverflow = 2,
}

All non-application errors will not be handled by the injected codeToReason and reasonToCode functions.

Additional context

Tasks

  • 1. Implement stopping WebSocketConnection with error codes and reasons
  • 2. Implement cancelling WebSocketStream on Readable or Writable sides independently
@CMCDragonkai
Copy link
Member

With the idea of having:

  • WebSocket
  • WebSocketConnection
  • WebSocketStream

This means there are 4 layers of errors:

  1. RPC layer
  2. Stream layer
  3. Connection layer
  4. Socket layer

In the case of the websocket, connection and socket is 1 to 1, so it's possible that there's no separate connection layer error. But it all depends on the user. The user should see a similar structure to how the js-quic works. We want the transport layers to function almost identically. So we encapsulate any of the details to achieve this!

@CMCDragonkai CMCDragonkai transferred this issue from MatrixAI/Polykey Aug 16, 2023
@amydevs amydevs changed the title More complex error codes logic for closing websockets More complex error codes logic for closing WebSocketConnections Sep 11, 2023
@amydevs amydevs changed the title More complex error codes logic for closing WebSocketConnections More complex error codes logic for closing WebSocketConnections/WebSocketStreams Sep 11, 2023
@CMCDragonkai
Copy link
Member

Done with #5.

@CMCDragonkai
Copy link
Member

@amydevs PK should make use of the relevant codes when you and @addievo open up the PK PR to integrate js-ws and js-rpc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Standard development r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management
Development

No branches or pull requests

2 participants