tor fails to handle half-closed TCP connections: it should forward data back on sockets that were shutdown(SHUT_WR) by client
I hit this situation when TCP client sent some data into the socket, then called "shutdown(fd, SHUT_WR)". Tor immediately initiates EOF in return.
However, "shutdown(fd, SHUT_WR)" only shuts down (sends EOF) in one direction. Another direction remains open, and tor should still send EOF into the circuit, receive response from TCP server, and forward it to the client through this half-closed connection, until the TCP server initiates EOF.
The easiest way to reproduce this is to run this script through torsocks:
echo "GET / HTTP/1.0
Connection: close
" | nc -N www.torproject.org 80
It returns no output. Remove "-N" and it will return an output. Run it without torsocks, and it will return output with and without "-N".
"-N" flag causes nc to call shutdown(SHUT_WR) once stdin had EOF.
So this script with -N option demonstrates how tor fails to handle half-closed TCP connections. (older versions of nc had no -N flag, and always called shutdown(SHUT_WR))
The correct behavior here is to keep writing response into such socket until 'write' returns some error condition.
To be fair, squid/DeleGate/nginx proxies all suffer from the same problem. But I believe, TOR should be better than them, and do things the right way.