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

fix: various connection bugs #25

Merged
merged 17 commits into from
Dec 11, 2023
Merged

fix: various connection bugs #25

merged 17 commits into from
Dec 11, 2023

Conversation

jackyzha0
Copy link
Member

@jackyzha0 jackyzha0 commented Dec 8, 2023

  • ws.onmessage needed more documentation on what it was doing
  • there was incorrect logging around websocket failure
  • update docs on Transport and Connection (with a diagram!)
  • transport related
    • only the first message sent by the client in a stream should have stream open bit
    • WebSocketServerTransport shouldn't close the underlying wss on .close() (but it should terminate all connected clients)
    • after the output stream in a server handler is closed, it should notify the client so the client can also close the output
    • client should respect the server-side sent stream close bit
  • added checks to make sure we cleanup streams, connections, and message handlers after closing

@jackyzha0 jackyzha0 requested a review from moudy December 9, 2023 05:48
Copy link
Contributor

@bradymadden97 bradymadden97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! good tests :)

transport.send(m);
}
})();

// transport -> output
const listener = (msg: OpaqueTransportMessage) => {
if (belongsToSameStream(msg)) {
if (isStreamClose(msg.controlFlags)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "stream close" msg wouldn't also contain normal message contents, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, stream close on the client means that message is the control message (it's kind of weird because its not the case for the server, can probably add an extra check here to make it consistent)

Comment on lines +71 to +73
await stream.promises.inputHandler;
stream.outgoing.end();
await stream.promises.outputHandler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we await these together?

Promises.all()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think it can actually, the input handler requires input to be ended but output to be open whereas output requires output to be ended

Comment on lines +130 to +132
// we ended, send a close bit back to the client
// only subscriptions and streams have streams the
// handler can close
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client stream can't be closed by server? what if it's like "ah you're sending me too much data!" I guess then it would instead be "just use a stream"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client stream hasn't been implemented yet haha

} catch (err) {
errorHandler(err);
}
})();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should throw here on unhandled procedure types

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would probably allow us to not have to set inputHandler to a resolved promise initially, which feels a bit weird.

this.ws.onmessage = (msg) => this.onMessage(msg.data as Uint8Array);

// take over the onmessage for this websocket
this.ws.onmessage = (msg) => transport.onMessage(msg.data as Uint8Array);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to remove these as eventually

@jackyzha0 jackyzha0 merged commit bf068db into main Dec 11, 2023
4 checks passed
@jackyzha0 jackyzha0 deleted the jackyzha0/connection-fixes branch December 11, 2023 00:34
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

Successfully merging this pull request may close these issues.

2 participants