Overview
| Artifact ID: | b4df16c944bee23a8ee55df6897a32e0b2a559b886b041eb16507f3c6197ad9b |
|---|---|
| Ticket: | b3905a822661d7ccb060926e81b832198ed415b5
Code Not Thread-Safe |
| User & Date: | anonymous 2021-04-12 19:42:27 |
Changes
- foundin changed to: "1.0.11"
- icomment:
The extension crashes when used in multiple threads. The problem is in UDP_CheckProc when it is determining whether it should read the socket. If there are multiple threads, the order in which the threads call this function is not deterministic, so it is possible that the wrong thread will read the socket.<br> <br> The solution is to verify the correct thread by changing: <pre> if (statePtr->packetNum > 0) {</pre> to:<br> <pre> if (statePtr->packetNum > 0 && statePtr->threadId == Tcl_GetCurrentThread()) {</pre> Here is a script that demonstrates the problem. The main thread reads a socket and a child thread writes a socket:<br> <pre> package require udp package require Thread proc handleRead {chan} { set data [read $chan] puts "received [string length $data] byte(s)" } set chan [udp_open] set port [fconfigure $chan -myport] fileevent $chan readable [list handleRead $chan] set tid [::thread::create] ::thread::send $tid "set port $port" ::thread::send $tid { package require udp set chan [udp_open] fconfigure $chan -remote [list localhost $port] -buffering none } while 1 { ::thread::send $tid {puts -nonewline $chan A} update } </pre> - login: "anonymous"
- mimetype: "text/html"
- private_contact changed to: "1c57e67924247fd7926e89348f266c081ec57db2"
- severity changed to: "Critical"
- status changed to: "Open"
- title changed to: "Code Not Thread-Safe"
- type changed to: "Code_Defect"