Message read incomplete
Review this Go TCP client snippet. It reads a length-prefixed message from a server.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1func readMessage(conn net.Conn) ([]byte, error) {
2 var header [4]byte
3 if _, err := conn.Read(header[:]); err != nil {
4 return nil, err
5 }
6 n := binary.BigEndian.Uint32(header[:])
7 buf := make([]byte, n)
8 if _, err := conn.Read(buf); err != nil {
9 return nil, err
10 }
11 return buf, nil
12}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.