Code RoomBusy loop on socket EOF
MediumPrep Room Coding #4290

Busy loop on socket EOF

Vibe & agenticDistributed systemsMid–Senior~16 min

An AI wrote this Python loop to consume a length-delimited stream over a socket. When the peer closes the connection mid-stream, the client busy-loops at 100% CPU. Find the bug, the trigger, and the fix.

Implement
drain_framed_stream(chunks: list[str]) → list[str]
Examples
in[["0003abc0003def"]]out["abc","def"]
in[["0005hello","","0005world"]]out["hello"]
in[["00"]]out[]
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it (tests, edge cases, reading critically), and how you’d re-prompt or decompose to get it right.

0:00 of about 16 min

Vibe & agentic: describe the solution in plain language (or narrate it) and the coach grades your approach.

Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.