1

Not sure if I have myself a problem with a python script I'm using. Basically, it spawns threads, each creating a tcp connections. Well the script finishes, i even check if any threads are still functioning, all of them return False ( not active which is good).

The issue is that, if I check ( I use CurPorts from nirsoft ) some tcp connections ( between 1 and 9 sometimes ) are still in established status and sometimes in Sent status. Is that a problem ?They die out eventually, but after several minutes. IS that on python's side fault, or basic windows procedure?

I close the sockets with S.close, if that's of any help. I'm not using daemon threads, just simple threads, and I just wait until all of them finish (t.join())

I need to know i I should worry or just let them be. reason is that they are eating up the ephemeral port number, and besides that i do not know if its keeping resources from me.

Would appreciate a noob friendly response.

Last Edit: I do use S.shutdown() before I send S.close() I do not do any error checking though, I have no idea how to go about doing that besides try:

2

1 Answer 1

1

The simple answer is that TCP connections need to be gracefully shutdown before being closed.

There are more details on how to call shutdown and close there:

Sign up to request clarification or add additional context in comments.

3 Comments

I do send S.shutdown() before S.close(), also I use non blocking sockets, but not by using select(), but by using setblocking(0) and settimeout(15) for the entire socket
Edit: So far, after script finishes, the Established and Sent tcp connections do die in about 1 and a half minutes in average. Is it normal? Should I just leave it like that and go with it? I changed shutdown() and close() to shutdown(1) and close()
Have a look at the third link. It explains in a table that you should (IIUC): shutdown(WR), and wait for FD_CLOSE, close().

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.