-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -415,14 +415,26 @@ export class ConnectionI { | |
let info = null; | ||
let response = null; | ||
try { | ||
if ((operation & SocketOperation.Write) !== 0 && this._writeStream.buffer.remaining > 0) { | ||
DEV: console.assert(this._sendStreams.length > 0); | ||
const currentMessage = this._sendStreams[0]; | ||
if (!this.write(this._writeStream.buffer, () => (currentMessage.isSent = true))) { | ||
DEV: console.assert(!this._writeStream.isEmpty()); | ||
return; | ||
if ((operation & SocketOperation.Write) !== 0) { | ||
if (this._writeStream.buffer.remaining > 0) { | ||
DEV: console.assert(this._sendStreams.length > 0); | ||
const completedSynchronously = this.write(this._writeStream.buffer); | ||
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; | ||
} | ||
|
||
if (!completedSynchronously) { | ||
DEV: console.assert(!this._writeStream.isEmpty()); | ||
return; | ||
} | ||
DEV: console.assert(this._writeStream.buffer.remaining === 0); | ||
} 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 commentThe 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. |
||
} | ||
DEV: console.assert(this._writeStream.buffer.remaining === 0); | ||
} | ||
if ((operation & SocketOperation.Read) !== 0 && !this._readStream.isEmpty()) { | ||
if (this._readHeader) { | ||
|
@@ -1156,13 +1168,18 @@ export class ConnectionI { | |
this._writeStream.swap(message.stream); | ||
|
||
// Send the message. | ||
const currentMessage = message; | ||
if ( | ||
this._writeStream.pos != this._writeStream.size && | ||
!this.write(this._writeStream.buffer, () => (currentMessage.isSent = true)) | ||
) { | ||
DEV: console.assert(!this._writeStream.isEmpty()); | ||
return response; // not done | ||
if (this._writeStream.pos != this._writeStream.size) { | ||
const completedSynchronously = this.write(this._writeStream.buffer); | ||
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. | ||
message.isSent = true; | ||
} | ||
|
||
if (!completedSynchronously) { | ||
DEV: console.assert(!this._writeStream.isEmpty()); | ||
return response; // not done | ||
} | ||
} | ||
|
||
// The message was sent synchronously, notify the message, remove it from the sent queue and keep going. | ||
|
@@ -1204,7 +1221,14 @@ export class ConnectionI { | |
|
||
TraceUtil.traceSend(stream, this._instance, this, this._logger, this._traceLevels); | ||
|
||
if (this.write(stream.buffer, () => (message.isSent = true))) { | ||
const completedSynchronously = this.write(stream.buffer); | ||
if (stream.buffer.remaining === 0) { | ||
// If the write call consumed the complete buffer, we assume the message is sent now for at-most-once | ||
// semantics. | ||
message.isSent = true; | ||
} | ||
|
||
if (completedSynchronously) { | ||
// Entire buffer was written immediately. | ||
message.sent(); | ||
return AsyncStatus.Sent; | ||
|
@@ -1448,9 +1472,9 @@ export class ConnectionI { | |
return ret; | ||
} | ||
|
||
write(buffer, bufferFullyWritten) { | ||
write(buffer) { | ||
const start = buffer.position; | ||
const ret = this._transceiver.write(buffer, bufferFullyWritten); | ||
const ret = this._transceiver.write(buffer); | ||
if (this._traceLevels.network >= 3 && buffer.position != start) { | ||
this._logger.trace( | ||
this._traceLevels.networkCat, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.