1

I have a script that spawns threads and then each thread is responsible for sending a web request and analyzing the response. If an error occurs, the thread will wait a few seconds and try the same request again. All requests are directed towards the same domain. When I start the script and open CurrPorts, I see that my total ports number keeps increasing all the way up to 10000 and more open ports and then eventually my adapter hangs. Oddly enough though, the threads work fine; they collect/analyze the data and move on. However, it seems they are leaving behind open ports or something. Anyone have any ideas as to what is going on?

Here is a screenshot showing all the open ports:

enter image description here

Here are the two main entries I see that are being repeated thousands of times:

Unknown 0   TCP 57660       192.168.1.118   443 https   52.84.14.175    server-52-84-14-175.ord54.r.cloudfront.net  Time Wait                       N/A             9 Nov. 2017 9:40:29 PM              
Unknown 0   TCP 58506       127.0.0.1   8888        127.0.0.1   PC  Time Wait                       N/A             9 Nov. 2017 9:40:29 PM              

Below is the relevant section of my code:

while(True):
    try:
        r = requests.post(url, headers=headers, data=data.encode('utf-8'), timeout=10)

        ### Do stuff. If request is valid, break. ###

    except Exception as e:
        with open(log_file,'a') as f:
                f.write(str(e) + '\n')
        time.sleep(15)

I figured that adding the timeout would resolve my dilemma, however it did not. Any enlightenment is greatly appreciated. Take care everyone.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
abaux
  • 13
  • 2

1 Answers1

1

Those connections are not open, they are in "Time Wait" state. This means the client has closed them but still needs to wait for a minimum amount of time. You can read more about why this happens, here:

John Zwinck
  • 239,568
  • 38
  • 324
  • 436