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

Handle close code&reason in libp2p-websocket #2021

Closed
dvdplm opened this issue Mar 29, 2021 · 2 comments
Closed

Handle close code&reason in libp2p-websocket #2021

dvdplm opened this issue Mar 29, 2021 · 2 comments

Comments

@dvdplm
Copy link
Contributor

dvdplm commented Mar 29, 2021

When a websocket is closed the closer may provide a code and optionally a reason for why the connection was closed (see rfc 5.5.1 and rfc 7.1.6 for details). Currently libp2p does not propagate this information to applications.

On the lower layer, soketto supports returning reason code](https://github.com/paritytech/soketto/blob/c02379dead28966a50c34dc4b2a6887d52c7ccd2/src/connection.rs#L365-L379) (but the user data is tossed away here).

We could change IncomingData to include a Close variant that carries the reason code&string and make sure the stream is closed properly after a Close frame was received.

The motivation for this is substrate-telemetry where an overloaded websocket server could use a way to tell connecting clients to back off, using the 1013 Try again later, or to inform them they are not allowed to connect at all using the 1008 Policy violation codes. Currently, clients connected using libp2p-websocket get a generic std::io::Error along the lines of Error: Custom { kind: Other, error: B(Custom { kind: Other, error: Closed }) } after a remote hung up on them.

See here for a full list of (semi-)standard status codes.

@dvdplm dvdplm changed the title Handle close code&reason in libp2p-websockets Handle close code&reason in libp2p-websocket Mar 29, 2021
@dvdplm
Copy link
Contributor Author

dvdplm commented Mar 30, 2021

On the lower layer, soketto supports returning reason code](https://github.com/paritytech/soketto/blob/c02379dead28966a50c34dc4b2a6887d52c7ccd2/src/connection.rs#L365-L379) (but the user data is tossed away here).

This is incorrect. soketto currently does not make the CLOSE frame reason code available to users. The code referenced above extracts the reason code to build a response CLOSE message (which is according to spec: the party receiving a CLOSE message must echo it back, https://tools.ietf.org/html/rfc6455#section-5.5.1), but cloaks the reason code/application data to calling code.

@mxinden
Copy link
Member

mxinden commented Feb 11, 2022

If I am not mistaken, this is fixed via #2319. I am closing here.

@mxinden mxinden closed this as completed Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants