-
Notifications
You must be signed in to change notification settings - Fork 593
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 JavaScript connection scheduling of heartbeats #3164
Conversation
if (this._writeStream.buffer.remaining === 0) { | ||
// If the write call consumed the complete buffer, we assume the message is sent now for | ||
// at-most-once semantics. | ||
this._sendStreams[0].isSent = true; | ||
} |
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.
This replaces the previous callback passed to write.
} else if (this._transceiver instanceof IdleTimeoutTransceiverDecorator) { | ||
// The writing of the current message completed, schedule a heartbeat in case the connection has | ||
// nothing more to write. | ||
this._transceiver.scheduleHeartbeat(); |
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.
This ensure that a heartbeat is scheduled even if write completes asynchronously. In this case Transceiver.write is not called and the decorator would not schedule one.
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.
Looks good.
A key part of the logic here is the "write" callback set by ConnectionI using setCallbacks:
this._transceiver.setCallbacks(
() => this.message(SocketOperation.Write), // connected callback
() => this.message(SocketOperation.Read), // read callback
() => this.message(SocketOperation.Write), // write callback
);
This ensures message(SocketOperation.Write)
is called when a write completes.
This PR fixes JavaScript connection to ensure hearbeats are scheduled even if the write completes asynchronously.
It also reworks how the connection checks if the transceiver write call consumed the completed buffer. There is no need for a callback or separate parameter as the transceiver advances the buffer and the call can check if there is any remaining data.