Opened 10 years ago

Closed 9 years ago

#2412 closed defect (fixed)

TorCtl isn't joining on _thread

Reported by: atagar Owned by: mikeperry
Priority: High Milestone:
Component: Torctl Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:


Very simple bug: the launch_thread function of torctl spawns two threads (self._thread and self._eventThread), but its close function only joins on self._eventThread [1]. The result is that the _thread lives a little longer (you can confirm this by checking threading.enumerate() after calling close):
1/19/2011 09:18:49 [INFO] [<_MainThread(MainThread, started -1216911680)>, <Thread(TorLoop, started daemon -1217868944)>]

This should be a trivial fix, though unfortunately it isn't the cause of the concurrency troubles I'm trying to track down. :(



Child Tickets

Change History (4)

comment:1 Changed 9 years ago by atagar

Priority: minormajor

Ah ha! Have the reason reason why _thread is sometimes joinable and other times locks the interpretor. The reason is that _read_reply call in the _loop only returns if we get something on the control port. This is causing problems for arm and is the reason my patch for 2812 is causing deadlock so upping the severity. I'm not sure of the best method for getting readline() to stop blocking - help would be appreciated.

09:25 < atagar> Uggg, this torctl _thread is annoying. If I don't join on it then I sometimes get interpretor shutdown exceptions ( but if I do then it ups arm's shutdown time (from instantaneous to around a second) and in some weird use cases causes deadlock.
09:27 < atagar> mikeperry: Daemon threads evidently cause the interpretor to whine if they aren't joined before shutdown. Any thoughts on how to make TorCtl's close method clean up its _thread?
09:28 < atagar> I'm not having much luck managing it externally :/
09:29 < atagar> Ah ha! Think I know what's happening
09:31 < atagar> The _read_reply call in the _loop method is returning when we receive an event so if I'm listening to BW events then it returns, hits the TorCtlClosed condition, and can be joined.
09:31 < atagar> since BW events happen every second this is why arm's shutdown time is now around a second
09:32 < atagar> but if we aren't listening for events then _read_reply never returns and the join on _thread causes arm to lock up
09:32 < atagar> hacky solution: somehow force tor to send something on its control port so torctl will wake up and shut down
09:34 < atagar> better solution: make the torctl close somehow stop blocking on readline()

comment:2 Changed 9 years ago by atagar

Status: newneeds_review

Fixed by adding a 20 ms timeout to socket reads and cleaning up _thread. This is in the 'bug2412' branch of my repo:

comment:3 Changed 9 years ago by mikeperry

Looks good. Merged.

comment:4 Changed 9 years ago by mikeperry

Resolution: fixed
Status: needs_reviewclosed
Note: See TracTickets for help on using tickets.