Opened 10 years ago

Closed 9 years ago

#1313 closed defect (duplicate)

Potential thread leak in TorCtl

Reported by: kaner Owned by: mikeperry
Priority: Low Milestone:
Component: Torctl Version: 0.2.1.24
Severity: Keywords:
Cc: kaner, nickm Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description (last modified by atagar)

TorCtl seems to leak threads, more exactly TorCtl.Connection leaks the _loop thread.

Here is simple python code to reproduce the leak:

---
#!/usr/bin/python

import socket
import time
from TorCtl import TorCtl

def doCheck():

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 9051))
control = TorCtl.Connection(sock)
control.authenticate("")
control.get_info(str("ns/id/6AF64BD1DF8B92D5194760C2256EBF80F70273DD"))
control.close()
del control
del sock

def main():

while True:

doCheck()
time.sleep(1)

if name == "main":

main()

---

Simply run this program and check the number of runnung threads via ps -eLf.

[Automatically added by flyspray2trac: Operating System: All]

Child Tickets

Change History (3)

comment:1 Changed 10 years ago by nickm

It's been a while since I wrote this code, but the intended behavior was that calling control.close() would set

isClosed to true, add a "CLOSED" to the queue, and close the socket. This way, the _loop function would exit

its read_reply because the socket had been closed, and pull from the queue, and find "CLOSED", and exit.

So some part of this clearly isn't working. The obvious first stop in debugging it would be to figure out which
part. Is closing the socket not making read_reply exit? Is one of the other steps not happening? IOW, what
is _loop doing here?

comment:2 Changed 10 years ago by nickm

Component: Tor - Tor clientTor - Torctl

comment:3 Changed 9 years ago by atagar

Description: modified (diff)
Resolution: Noneduplicate
Status: newclosed

I just retested this with my branch and it seems to be working. Most likely this was due to an orphaned _thread so this is being fixed by:
https://trac.torproject.org/projects/tor/ticket/2412

Note: See TracTickets for help on using tickets.