--------------------- PatchSet 6453 Date: 2008/01/05 21:25:44 Author: chtsanti Branch: async-calls Tag: (none) Log: When a socket is closed then it is possible that remains AsyncCalls to be executed which will try to perform operation on the closed socket. This patch does not close the socket when comm_close called but instead schedules the socket closing as an AsyncCall operation Members: src/comm.cc:1.81.4.16->1.81.4.17 Index: squid3/src/comm.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.cc,v retrieving revision 1.81.4.16 retrieving revision 1.81.4.17 diff -u -r1.81.4.16 -r1.81.4.17 --- squid3/src/comm.cc 29 Dec 2007 15:24:40 -0000 1.81.4.16 +++ squid3/src/comm.cc 5 Jan 2008 21:25:44 -0000 1.81.4.17 @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.81.4.16 2007/12/29 15:24:40 chtsanti Exp $ + * $Id: comm.cc,v 1.81.4.17 2008/01/05 21:25:44 chtsanti Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -1374,6 +1374,36 @@ } } +void +comm_close_complete(int fd, void *data) +{ + fde *F = &fd_table[fd]; +#if USE_SSL + + if (F->ssl) { + SSL_free(F->ssl); + F->ssl = NULL; + } + +#endif + fd_close(fd); /* update fdstat */ + + close(fd); + + if (AbortChecker::Instance().isMonitoring(fd)) + AbortChecker::Instance().stopMonitoring(fd); + + fdc_table[fd] = AcceptFD(fd); + + statCounter.syscalls.sock.closes++; + + /* When an fd closes, give accept() a chance, if need be */ + + if (fdNFree() >= RESERVED_FD) + AcceptLimiter::Instance().kick(); + +} + /* * Close the socket fd. * @@ -1439,31 +1469,17 @@ F->pconn.pool->count(F->pconn.uses); comm_empty_os_read_buffers(fd); + -#if USE_SSL - - if (F->ssl) { - SSL_free(F->ssl); - F->ssl = NULL; - } - -#endif - fd_close(fd); /* update fdstat */ - - close(fd); - - if (AbortChecker::Instance().isMonitoring(fd)) - AbortChecker::Instance().stopMonitoring(fd); - - fdc_table[fd] = AcceptFD(fd); - - statCounter.syscalls.sock.closes++; + AsyncCall::Pointer call=commCbCall(5,4, "comm_close_complete", + CommCloseCbPtrFun(comm_close_complete, NULL)); + comm_add_close_handler(fd, call); + typedef CommCloseCbParams Params; + Params ¶ms = GetCommParams(call); + params.fd = fd; + ScheduleCallHere(call); PROF_stop(comm_close); - /* When an fd closes, give accept() a chance, if need be */ - - if (fdNFree() >= RESERVED_FD) - AcceptLimiter::Instance().kick(); } /* Send a udp datagram to specified TO_ADDR. */