Closing right after an early error response

A client sends a 4KB request and then blocks in recv() waiting for the response. The Linux server below reads only the request line, decides the request is bad, writes a complete 400 response, and closes. The client intermittently gets ECONNRESET from recv() and never sees the 400. What causes that?

main.cpp
// Server, per connection:
char line[256];
read_request_line(cfd, line, sizeof(line));  // ~3.8KB of the request still unread
write(cfd, resp400, resp400_len);            // full response, returns resp400_len
close(cfd);

34 of 45 in Networking