this bug is reproduced with random chance
lsof outputs:
python2.6 26281 ircbot 3u IPv4 239290106 TCP 192.168.10.1:50849->192.168.10.1:9050 (CLOSE_WAIT)
gdb
(gdb) bt
#0 0xb7d175e3 in ?? () from /lib/libpthread.so.0
#1 0xb7d17de0 in recv () from /lib/libpthread.so.0
#2 0xb7ee55f8 in handle_request (conn=0x8895098) at tsocks.c:986
#3 0xb7ee766c in connect (__fd=3, __addr=0xbff0a6e4, __len=16) at tsocks.c:330
#4 0xb7afbec9 in internal_connect (s=0x882b2c8, addr=0x0, addrlen=16, timeoutp=0xbff0a754)
at /usr/src/debug/dev-lang/python-2.6.2-r1/Python-2.6.2/Modules/socketmodule.c:1938
#5 0xb7afc11e in sock_connect (s=0x882b2c8, addro=0x87ff36c)
at /usr/src/debug/dev-lang/python-2.6.2-r1/Python-2.6.2/Modules/socketmodule.c:2033
(gdb) fr
#2 0xb7ee55f8 in handle_request (conn=0x8895098) at tsocks.c:986
986 rc = recv(conn->sockid, conn->buffer + conn->datadone,
(gdb) l
976 show_msg(MSGDEBUG, "Sent %d bytes of %d bytes in buffer, return code is %d\n",
977 conn->datadone, conn->datalen, rc);
978 return(rc);
979 }
980
981 static int recv_buffer(struct connreq *conn) {
982 int rc = 0;
983
984 show_msg(MSGDEBUG, "Reading from server (expecting %d bytes)\n", conn->datalen);
985 while ((rc == 0) && (conn->datadone != conn->datalen)) {
986 rc = recv(conn->sockid, conn->buffer + conn->datadone,
987 conn->datalen - conn->datadone, 0);
988 if (rc > 0) {
989 conn->datadone += rc;
990 rc = 0;
991 } else {
992 if (errno != EWOULDBLOCK)
993 show_msg(MSGDEBUG, "Read failed, %s\n", strerror(errno));
994 rc = errno;
995 }
version: from gentoo's tsocks-1.8_beta5-r5.ebuild
# uname -a
Linux smgpserver 2.6.14-hardened-r8 #3 SMP Sat Jun 24 10:05:25 CST 2006 i686 Intel(R) Celeron(R) CPU 2.40GHz GenuineIntel GNU/Linux
recv() return rc <= 0 that make the flow goest to rc=errno, i'm not sure why but errno is zero. why not simply check rc and break?
while ((conn->datadone != conn->datalen)) {
.......
else {
rc = errno;
if (errno is not ewouldblock nor eagain) break;
showdebugmsg();
}
}