tcp networking question (CLOSE_WAIT)

Martin A. Brown martin at
Thu Feb 25 13:56:00 EST 2016

Hello again Ray,

>> >I'm new to python networking. I am waiting TCP server/client app by 
>> >using python built-in SocketServer. My problem is if client get 
>> >killed, then the tcp port will never get released, in CLOSE_WAIT
>> I did not thoroughly review your code (other than to see that you 
>> are not using SO_REUSEADDR).  This is the most likely problem.
>> Suggestion:
>>   man 7 socket
>> Look for SO_REUSEADDR.  Then, apply what you have learned to your 
>> code.
>it's not I can't bind the address, my problem is: server is long 
>run. if client die without "disconnect" then server will leak one 

Sorry for my trigger-happy, and incorrect reply.

After so many years, I should know better than to reply without 
completely processing questions.  Apologies.

>by using the built-in thread socket server. the extra tcp port are 
>opened by built-in class itself. if the handler() is finish 
>correctly (the line with break) then this socket will get cleaned 
>up. but if client dies, then I am never get out from that True 
>loop. so the socket will keep in close_wait
>I fond the issue. it's my own stupid issue.
>i did "continue" if no data received.
>just break from it then it will be fine

Well, I'm glad you found the issue.

Best of luck,


Martin A. Brown

More information about the Python-list mailing list