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(server): message handling order when using beforeHandleMessage (#880) #901

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

RubaXa
Copy link
Contributor

@RubaXa RubaXa commented Feb 11, 2025

No description provided.


message.writeVarString(documentName)

this.callbacks.beforeHandleMessage(this, data)
.then(() => {
this.nextProcessBeforeHandleMessage()

Choose a reason for hiding this comment

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

The ordering of things here seems a bit off to me: you trigger the processing of a next message before you've processed this one (below).

Choose a reason for hiding this comment

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

The invocation of this.nextProcessBeforeHandleMessage will initiate a new async sequence and to me it seems possible that things go out-of-order again.

@@ -41,6 +41,10 @@ export class Connection {

logger: Debugger

private beforeHandleMessageQueue: Uint8Array[] = []
Copy link

@raimohanska raimohanska Feb 16, 2025

Choose a reason for hiding this comment

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

You might be able to do with just 1 additional state variable if you shifted the message only after successfully processing it.

}

/** Process an incoming message */
private processBeforeHandleMessage(data: Uint8Array): void {

Choose a reason for hiding this comment

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

The name of the method is out of sync with the comment. I like the comment more, as what this methos does is process an incoming message after applying the beforeHandleMessage hooks.

}

/** Process an incoming message */
private processBeforeHandleMessage(data: Uint8Array): void {

Choose a reason for hiding this comment

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

I would prefer using async-await syntax for this method. This would allow you to use a while (this. beforeHandleMessageQueue.length > 0 loop.

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