in reply to POE::Component::Client::HTTP, Keepalive, FIN_WAIT_2

FIN_WAIT_2 happens when the local end of a socket is closed and the operating system is waiting for a signal that the remote end has closed their side. In your case, enough connections haven't that the operating system's socket table has filled, and new sockets can't be allocated.

I have a possible solution, but I don't have anything to test it against. If you could provide a test case that reliably triggers the problem, I can debug it quickly and turn around a better answer.

Meanwhile I have taken a guess at a solution, but you'll have to test it for me. If you can, please edit Client/Keepalive.pm (not Connection/Keepalive.pm). There should be a comment around line 582:

  # Build a connection object around the socket.

I need you to add these three lines before that comment (wherever it may be):

use Socket qw(SOL_SOCKET SO_LINGER); setsockopt($socket, SOL_SOCKET, SO_LINGER, pack("sll",1,0,0)) or die +( "setsockopt: $!" + );
When it comes time to close that socket, it should not linger in FIN_WAIT_2.

If that works for you, keep it free of charge. Also, let me know so I can include it in a future release.

Thank you.

Replies are listed 'Best First'.
Re^2: POE::Component::Client::HTTP, Keepalive, FIN_WAIT_2
by nuclon (Acolyte) on Nov 25, 2008 at 08:04 UTC

    it seems it helped but now I have another behaviour :)

    Script works well some time. Then I start to get "connect error 60: Operation timed out", see a lot of "TIME_WAIT" connections in netstat (and no other connections at all) in this moment. after few minutes all TIME_WAIT connections dissapear and I see empty output of netstat, but script still log "Operation timed out".

    I've turned on DEBUG in Client::Keepalive and got a lot of following messages at the time when netstat output is empty:

    ALLOCATE: enqueuing request for http:gdata.youtube.com:80 at /home/ser +vice/perl/lib/site_perl/5.8.8/POE/Component/Client/Keepalive.pm line +377. ... CON: request from session 5 for address 74.125.95.102 timed out at /ho +me/service/perl/lib/site_perl/5.8.8/POE/Component/Client/Keepalive.pm + line 507.

      I'm not sure I can debug this one from a distance. Can you provide a minimal test case to reproduce the problem? Ideally it would be something I can run without installing proprietary code or data.

      By the way, I released new versions of POE::Component::Client::Keepalive and POE::Component::Client::HTTP with a modified version of the SO_LINGER code and some other bug fixes.