rsocket / rsocket-js

JavaScript implementation of RSocket

Home Page:https://github.com/rsocket/rsocket-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Protocol-level connection errors result in `CLOSED` status instead of `ERROR`

ada-waffles opened this issue · comments

Expected Behavior

When a connection is closed due to a protocol-level error (such as rejected SETUP), the connection status should be set to ERROR.

As per the documentation here:

* - CLOSED: when the connection has been explicitly closed via `close()`.
* - ERROR: when the connection has been closed for any other reason.

Actual Behavior

Protocol-level connection errors result in the connectionStatus() Flowable emitting a status of CLOSED.

Steps to Reproduce

Minimal reproduction: https://github.com/duke9509/rsocket-js-error-status-repro

The server just immediately rejects every SETUP frame.

Output from the client:

Attempting to connect to server...
Initial connection established. SETUP frame sent.
Connection status: { kind: 'CONNECTED' }
Connection status: { kind: 'CONNECTED' }
Connection status: { kind: 'CLOSED' }

(I have no idea why CONNECTED is seemingly emitted twice, but I'm not too concerned about it and it seemed orthogonal to this issue so I didn't bother to dig into it)

Possible Solution

I can think of at least a couple approaches to fixing this. The simplest in my mind is to ammend DuplexConnection#close and its implementations to accept an optional error argument indicating that the connection is being closed due to an error and should behave as such.

This seems easy enough to implement and I've already tested it locally, so I plan to submit a PR.

Your Environment

  • RSocket version(s) used: 0.0.25
  • Other relevant libraries versions (eg. netty, ...): N/A
  • Platform (eg. JVM version (javar -version) or Node version (node --version)): Node 15.14.0
  • OS and version (eg uname -a): macOS Big Sur 11.2.3