Skip to content

Fix: JSON-RPC message loss when TCP reads contain heartbeats - #323

Open
bbdu3 wants to merge 1 commit into
modelcontextprotocol:mainfrom
bbdu3:fix/network-heartbeat-framing
Open

bbdu3 wants to merge 1 commit into
modelcontextprotocol:mainfrom
bbdu3:fix/network-heartbeat-framing

Conversation

@bbdu3

@bbdu3 bbdu3 commented Nov 6, 2026 •

Copy link
Copy Markdown

Summary

NetworkTransport previously skipped an entire receive chunk when it began with a heartbeat, discarding any following JSON-RPC messages. Parse buffered frames so the heartbeat is consumed without losing subsequent messages.

Fixes #322.

Changed

  • Move heartbeat detection into the buffered receive loop.
  • Consume only the complete 12-byte heartbeat, then continue processing remaining bytes.
  • Retain incomplete frames for the next read.
  • Add 14 parameterized regression cases covering coalesced heartbeats and messages, plus splits across the heartbeat and following JSON.
  • Preserve public APIs and the existing wire format.

Test

  • Python behavior-model checks: all 14 regression inputs fail under the original logic and pass under the revised logic. Additional fragmentation and control cases passed.
  • git diff --check passed.

Signed-off-by: bbdu3 <ergouyang854@gamil.com>
@bbdu3
bbdu3 requested a review from a team as a code owner November 6, 2026 06:10
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.

NetworkTransport drops a JSON message when a TCP receive contains a heartbeat followed by the message

1 participant