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:

Ichabod Crane
  • 127
  • 2
  • 9
  • Would help to include a minimal code example which demonstrates the problem. – Aya Jun 17 '13 at 12:06
  • 1
    possible duplicate of [How do you close TCP connections gracefully without exceptions?](http://stackoverflow.com/questions/1336709/how-do-you-close-tcp-connections-gracefully-without-exceptions) – Didier Trosset Jun 17 '13 at 12:13

1 Answers1

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:

Community
  • 1
  • 1
Didier Trosset
  • 36,376
  • 13
  • 83
  • 122
  • 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 – Ichabod Crane Jun 17 '13 at 12:25
  • 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() – Ichabod Crane Jun 17 '13 at 13:25
  • 1
    Have a look at the third link. It explains in a table that you should (IIUC): shutdown(WR), and wait for FD_CLOSE, close(). – Didier Trosset Jun 17 '13 at 14:25