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 JavaScript connection scheduling of heartbeats #3164

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

pepone
Copy link
Member

@pepone pepone commented Nov 18, 2024

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.

Comment on lines +422 to +426
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;
}
Copy link
Member Author

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();
Copy link
Member Author

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.

Copy link
Member

@bernardnormier bernardnormier left a 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.

@pepone pepone merged commit 7353f68 into zeroc-ice:main Nov 18, 2024
19 checks passed
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Dec 26, 2024
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
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.

3 participants