-
-
Notifications
You must be signed in to change notification settings - Fork 139
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
base: main
Are you sure you want to change the base?
Conversation
|
||
message.writeVarString(documentName) | ||
|
||
this.callbacks.beforeHandleMessage(this, data) | ||
.then(() => { | ||
this.nextProcessBeforeHandleMessage() |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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[] = [] |
There was a problem hiding this comment.
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 shift
ed the message only after successfully processing it.
} | ||
|
||
/** Process an incoming message */ | ||
private processBeforeHandleMessage(data: Uint8Array): void { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
No description provided.