On Thu, Jan 13, 2022 at 7:36 PM Thomas Munro <thomas.mu...@gmail.com> wrote: > ... First I tried to use recv(fd, &c, 1, > MSG_PEEK) == 0 to detect EOF, which seemed to me to be a reasonable > enough candidate, but somehow it corrupts the stream (!?),
Ahh, that'd be because recv() and friends are redirected to our wrappers in socket.c, where we use the overlapped Winsock API (that is, async network IO), which is documented as not supporting MSG_PEEK. OK then. Andres and I chatted about this stuff off list and he pointed out something else about the wrappers in socket.c: there are more paths in there that work with socket events, which means more ways to lose the precious FD_CLOSE event. I don't know if any of those paths are reachable in the relevant cases, but it does look a little bit like the lack of graceful shutdown might have been hiding a whole class of event tracking bug.