Skip to content

Fix JSON parsing in reliable_recv() #1

Description

@anujbolewar

Right now, reliable_recv() reads 1024 bytes and blindly calls json.loads(). TCP is a byte stream, not a message boundary protocol. If two JSON payloads arrive in the same 1024-byte chunk, json.loads() crashes and we spin into an infinite ValueError loop.

The Fix:

Prefix every outgoing message with a 4-byte length header (use struct.pack).
On receive, read exactly 4 bytes to get the payload length N.
Read exactly N bytes into a buffer, then cleanly json.loads() it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions