Opened 3 years ago

Closed 3 years ago

#14048 closed defect (fixed)

from stem.util.connection import get_connections (v1.3) sometimes throws an exception

Reported by: toralf Owned by: atagar
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

eg for an exit relay of ~ 2000 inbound+outbound connections sometimes the following code snippet

...
   try:
      connections = get_connections(resolver, process_pid = pid, process_name = 'tor')
      print " connections: %4i" % len(connections)
...
    except Exception as exc:
      print exc

gives :

 platform supports connection resolution via: proc, netstat, lsof, ss (picked: proc)
 1 instance(s) of tor: 2223 (picked: 2223)
unable to determine file descriptor destination: /proc/2223/fd/985

IMO if the "proc" resolver fails due to some race conditions for a particular connection it should deliver data for all the other connections.

Child Tickets

Change History (5)

comment:1 Changed 3 years ago by atagar

Hi toralf. If this is easily reproduceable would you mind dropping the catch clause so we can get a stacktrace?

comment:2 Changed 3 years ago by toralf

Here you go :

tfoerste@t44 ~/devel/ooni-probe $ ssh tfoerste@tor-relay "sudo grep -e '^#ExitPolicy' /etc/tor/torrc; sudo /home/tfoerste/info.py; echo $?"
#ExitPolicy reject *:* # comment this line to allow exit
#ExitPolicy accept *:22         # ssh
 Tor version is 0.2.5.10 (git-42b42605f8d8eac2)
 read 54044 MiB, wrote 55492. MiB
 platform supports connection resolution via: proc, netstat, lsof, ss (picked: proc)
 1 instance(s) of tor: 2223 (picked: 2223)
 6662 relays known
Traceback (most recent call last):
  File "/home/tfoerste/info.py", line 92, in <module>
    main()
  File "/home/tfoerste/info.py", line 48, in main
    connections = get_connections(resolver, process_pid = pid, process_name = 'tor')
  File "/usr/lib64/python2.7/site-packages/stem/util/connection.py", line 177, in get_connections
    return [Connection(*conn) for conn in stem.util.proc.connections(process_pid)]
  File "/usr/lib64/python2.7/site-packages/stem/util/proc.py", line 372, in connections
    raise exc
IOError: unable to determine file descriptor destination: /proc/2223/fd/1339
0

comment:3 Changed 3 years ago by atagar

Thanks toralf! Agreed, the connection resolver should simply skip descriptors that disappear in the middle of reading proc. Pushed a little fix...

https://gitweb.torproject.org/stem.git/commit/?id=539b6353114e95fa805f55c36562502eec76534e

Would you mind giving it a try to see if it does the trick?

comment:4 Changed 3 years ago by toralf

ofc (patching is easy under Gentoo, more or less somebody just have to copy the git patch into /etc/portage/patches/net-libs/stem-1.3.0 and re-emerge stem).

The patch applies fine, works, so far no back traces till now.

Will give it a try over the next days (usually the issue happens when the tor relay is under pressure by a third party relaying a huge amount of port scans over it - which is the case since about 3-4 weeks)

comment:5 Changed 3 years ago by atagar

Resolution: fixed
Status: newclosed

Great! Feel free to reopen with an updated stacktrace if you run into any further issues.

Note: See TracTickets for help on using tickets.