Overview
| Artifact ID: | 17917480180627a01fe1672bfac842582d70e812 |
|---|---|
| Ticket: | 3545363fffffffffffffffffffffffffffffffff
socket/vwait hang in io-53.10 and socket.test |
| User & Date: | twylite on 2012-07-20 17:38:22 |
Changes
- icomment:
I've uploaded td-patch-3545363-1.diff, a patch against branch bug-3545363 checkout a1fbf5e7. It passes all (relevant) tests on Windows 7 64-bit (32-bit tclsh) with no crashes or hangs. Bug 3545363 is caused by multiple code locations treating infoPtr->sockets as a single fd rather than a linked list of fds. For connected sockets (i.e. not server listening sockets) this is a valid assumption; but other code locations such as TcpCloseProc() and SocketProc() must handle all socket types and treat infoPtr->sockets as a list. TcpCloseProc() was leaking memory by not freeing the infoPtr->sockets linked list. Adding the ckfree() exposed a bug where TcpAccept() was dereferencing a released pointer. If TcpAccept() accepts the socket and calls the infoPtr->acceptProc() then Tcl code (the -server script) is evaluated. In socket_any-2.10 the Tcl script closes the server socket (frees infoPtr->sockets and infoPtr). After the eval, TcpAccept() returns up the stack to SocketEventProc() which is still walking fds (now freed). Before adding ckfree() to TcpCloseProc() fds was leaked so the for loop called TcpAccept() again which would get INVALID_SOCKET and write two values into fds->infoPtr (previously freed), but this overwrite wasn't causing a crash (just invisible corruption). This has been fixed by having the accept logic terminate the loop after one socket is accepted. To ensure locking is handled correctly the accept() and infoPtr->readyEvents manipulation has been moved to SocketEventProc(), with TcpAccept() just handling the setup of the client channel after the socket is accepted. Having all the logics and readyEvents manipulation in one place should also improve code maintainability. Slight refactoring in CreateSocket() and NewSocketInfo() to extract common logic to add to the infoPtr->sockets linked list, now in AddSocketInfoFd(). This also makes clearer what CreateSocket() is trying to do.
- login: "twylite"
- mimetype: "text/plain"
- username: "twylite"