<div dir="ltr"><p dir="ltr"></p>Hi Damian and thanks for your answer. Actually I only need 2 (at most) different IPs at a time from different countries, that's why I need to use 2 instances of my script with separate circuits. I have to test a CGI script on a server of mine and each request is delayed 2 seconds from the next one, so I think this situation shouldn't be an issue for the TOR network. So we don't have 400xN but 1request x 2instances every 2 seconds. In netstat i see at most 4 established connections (about tor) and even socklist gives me the same result.<br>

<br>Btw, let's consider only one instance of the script. It blocks at N~=200 requests (it makes a get first - N/2 in total - and then a post - N/2 in total - both blocking requests). Enabling log, the last message is:<br>

[debug] parse_socks(): socks5: ipv4 address type<div><br><div>Previous similar messages were followed by:</div><div>[debug] connection_ap_handshake_process_socks(): socks handshake not all here yet. #or Client asked for [scrubbed]:80</div>

<div><div>[debug] connection_ap_handshake_process_socks(): entered.</div><div>[debug] connection_ap_handshake_process_socks(): socks handshake not all here yet.</div><div>[debug] conn_write_callback(): socket 64 wants to write.</div>

<div>...</div><div><br></div><div style>But once i got:</div><div style>[warn] Your application (using socks5 to port 80) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead. For more information, please see <a href="https://wiki.torproject.org/TheOnionRouter/TorFAQ#SOCKSAndDNS">https://wiki.torproject.org/TheOnionRouter/TorFAQ#SOCKSAndDNS</a><br>

</div><div style><br></div><div style>So it seems that the script gets stuck here:</div><div style>connection_ap_handshake_rewrite_and_attach()</div><div class="gmail_quote"><br></div><div class="gmail_quote" style>Thanks a lot Damian, all</div>

<div class="gmail_quote" style><br></div><div class="gmail_quote" style>Eduard</div><div class="gmail_quote"><br></div><div class="gmail_quote">Il giorno 02/ago/2013 19:41, "Damian Johnson" <<a href="mailto:atagar@torproject.org" target="_blank">atagar@torproject.org</a>> ha scritto:<br type="attribution">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



Hi Eduard. On first glance I'm not aware of any resource that would be<br>
exhausted by this after 200 iterations. Does the issue repro if you<br>
just do 400 GETs or 400 POSTs, or does the problem only arise when you<br>
do a combination of 200 of each? Have you tried running netstat or<br>
another connection resolver when it gets stuck to see if you have 400<br>
open connections (that is to say, checking that this is terminating<br>
the connections as expected)?<br>
<br>
On a side note I'm a little concerned about you running multiple<br>
instances of this script to run through multiple relays. 400 requests<br>
x N instances would be quite a bit of traffic to dump on the network.<br>
In addition, each instance is downloading the full tor consensus and<br>
microdescriptors since it does not share a data directory. What<br>
exactly is the goal of your script?<br>
<br>
Cheers! -Damian<br>
<br>
On Thu, Aug 1, 2013 at 10:00 AM, Eduard Natale <<a href="mailto:eduard.natale@gmail.com" target="_blank">eduard.natale@gmail.com</a>> wrote:<br>
> Hello guys,<br>
><br>
> I had a problem and currently I'm not able to solve it. So, here I am ;) I<br>
> have a python script that uses python-stem to create and handle a tor<br>
> instance (on a defined port). What it does is retrieving (using a  HTTP GET)<br>
> a web page and submitting information (using HTTP POST messages).<br>
> Basically i use tor because I need to test this server from different IP<br>
> addresses with more requests in parallel. What I also do is keeping trace of<br>
> Cookies. Here's a sample of the code I use, based on the example on stem<br>
> website <a href="https://stem.torproject.org/tutorials/to_russia_with_love.html" target="_blank">https://stem.torproject.org/tutorials/to_russia_with_love.html</a> (to<br>
> have more parallel requests, i launch the script many times with different<br>
> socks_port value):<br>
> ----------------------------<br>
> import socket, socks, stem.process<br>
> import mechanize, cookielib<br>
><br>
> SOCKS_PORT = 9000<br>
> DATA_DIRECTORY = "TOR_%s" % SOCKS_PORT<br>
> socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', SOCKS_PORT)<br>
> socket.socket = socks.socksocket<br>
><br>
> tor_process = stem.process.launch_tor_with_config(<br>
>           config = {<br>
>             'SocksPort': str(SOCKS_PORT),<br>
>             'ControlPort': str(SOCKS_PORT+1),<br>
>             'DataDirectory': DATA_DIRECTORY,<br>
>             'ExitNodes': '{it}',<br>
>           },<br>
>         )<br>
><br>
> # initialize python mechanize, with cookies (it works exactly like urllib2,<br>
> urllib3, etc. already tried...)<br>
> br = mechanize.Browser()<br>
> cj = cookielib.LWPCookieJar()<br>
> br.set_cookiejar(cj)<br>
> ...<br>
><br>
> for number in num_list:<br>
>   req = br.open_novisit("<a href="http://example.com" target="_blank">http://example.com</a>") #_1_<br>
>   res = req.read()<br>
>   print res<br>
>   req.close()<br>
>   req2 = br.open("<a href="http://example.com/post_to_me" target="_blank">http://example.com/post_to_me</a>", data_to_post) #_2_<br>
>   res2 = req2.read()<br>
>   req2.close()<br>
> --------------------------------<br>
><br>
> And that's it. The problem occurs on the lines i marked as _1_ and _2_:<br>
> basically when it reaches around 200 requests, it seems to block<br>
> undefinitely, waiting for a response that never comes. Of course,<br>
> wiresharking doesn't work because it's encrypted. The same stuff, without<br>
> TOR, works perfectly. So, why does it stuck at about 200 requests!? I tried<br>
> to:<br>
><br>
> 1. Telnet on control port, forcing to renew circuits with SIGNAL NEWNYM<br>
> 2. instantiating mechanize (urllib2, 3, whatever) in the loop<br>
> 3. ...i don't remember what else<br>
><br>
> I thought it could be a local socket connection limit: actually without TOR,<br>
> i see in wireshark the source port changes every time a request is<br>
> performed. But actually i don't know if the problem is in using the same<br>
> source port every time (but i don't think so) and if so, should I close the<br>
> current socket and open a new one? Should I kill the tor process? I can't<br>
> exaplain myself why...<br>
> What I only know is: *when the script stucks, if i kill the python process<br>
> (ctrl+c) and then re-launch, it starts working again.*. I've seen that it's<br>
> possible to set the value of TrackHostExitsExpire, is it useful in my case?<br>
><br>
> Thanks in advance to whoever can help me!!<br>
> Ed<br>
><br>
><br>
> _______________________________________________<br>
> tor-dev mailing list<br>
> <a href="mailto:tor-dev@lists.torproject.org" target="_blank">tor-dev@lists.torproject.org</a><br>
> <a href="https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev" target="_blank">https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev</a><br>
><br>
_______________________________________________<br>
tor-dev mailing list<br>
<a href="mailto:tor-dev@lists.torproject.org" target="_blank">tor-dev@lists.torproject.org</a><br>
<a href="https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev" target="_blank">https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev</a><br>
</blockquote></div>
</div></div></div>