Overview
| Artifact ID: | eb7abffe317359c188181b20ac3b3f997f0e0c2a |
|---|---|
| Ticket: | 3056775fffffffffffffffffffffffffffffffff
Socket -server stops accepting connections under load |
| User & Date: | twylite on 2010-09-23 05:31:21 |
Changes
- icomment:
Hi, > Can you provide us with a unified diff for the patch ? Or context diff. Will do so tomorrow, I don't have the codebase on this PC. > Anything which tells me not just the line numbers, but also shows the > relevant code and things around it. Using the line number with Tcl Head it > seems that you are putting the locks around the statement > > "infoPtr->acceptEventCount--;" Sounds about right. > Except that there are other statements also modifying/querying > acceptEventCount and possinbly should be locked as well. Yes. I seem to recall checking that the other modifications were safe. But I also recall adding info about this to the bug report, which I clearly didn't do :( I guess I'll look again. > Another issue I have is that it is extremely unclear how this structure is > modified by multiple threads. This may be my own non-knowledge of the > (windows) notifier, so I hope you can enlighten me. The trick, if I understand it, is that each thread has a socketList in thread-specific-data (tsdPtr), and also a "co-thread" (tsdPtr->socketThread) to receive WSAAsyncSelect() events into SocketProc(). SocketProc() calls Tcl_ThreadAlert() to queue the events that will be handled by SocketEventProc(). The tsdPtr->socketListLock is used to prevent race conditions between the interp thread and "co-thread" while accessing tsdPtr. > First, the socket should be owned by a single thread and no other should > access it. The socket is accessed by the co-thread. tsdPtr is used to communicate between the interp thread and the co-thread. This is a race condition between those threads. One example of the race condition is when there is a context switch immediately after checking the acceptEventCount in TcpAccept(): Thread1 (TcpAccept) : infoPtr->acceptEventcount--; Thread1 (TcpAccept) : if (infoPtr->acceptEventCount <= 0) { ** context switch ** Thread2 (SocketProc) : infoPtr->readEvents |= event; Thread2 (SocketProc) : ... ** context switch ** Thread1 (TcpAccept) : infoPtr->readEvents &= ~(FD_ACCEPT); - login: "twylite"
- mimetype: "text/plain"
- username: "twylite"