Menu

#558 CLOSE_WAIT problem

closed-works-for-me
https (67)
5
2013-06-21
2005-12-09
No

curl 7.15.1 (i686-pc-linux-gnu) libcurl/7.15.1
OpenSSL/0.9.8a zlib/1.1.3
Protocols: tftp ftp gopher telnet dict ldap http file
https ftps
Features: IPv6 Largefile NTLM SSL libz

In multithread application several threads is doing
https requests to localhost, every request is
(curl_easy_init->curl_easy_perform-
>curl_easy_cleanup), sometime libCurl (or openssl??)
do not close sockets and after a bunch of requests i
see handreds of CLOSE_WAIT strings in nestat.
CLOSE_WAIT disappears if i close my application.

i checked, curl_easy_cleanup called EVERY TIME.

Evgeny

Discussion

  • Daniel Stenberg

    Daniel Stenberg - 2005-12-09

    Logged In: YES
    user_id=1110

    How many threads? How many sockets are in CLOSE_WAIT?

    libcurl keep sockets "open" by default after a
    curl_easy_perform(), to be prepared to re-use the connection
    on a subsequent call to it again. But if the call doesn't
    come within a limited time, the remote server might decide
    to close down the connection anyway and the socket ends up
    in CLOSE_WAIT.

    You can avoid this by forcing libcurl to close the sockets
    after use, which then of course disables persistent
    connections on subsequent calls.

    Can you reproduce this problem with a small stand-alone app
    that you can provide the source for?

     
  • Evgeny Sabelsky

    Evgeny Sabelsky - 2005-12-09

    Logged In: YES
    user_id=738516

    Ok, i'll try to reproduce it in a small app.
    How can i force close ? I have checked _cleanup method,
    seems like it should cleans connections by

    while(-1 != ConnectionKillOne(data))
    ; /* empty loop */

     
  • Daniel Stenberg

    Daniel Stenberg - 2005-12-09

    Logged In: YES
    user_id=1110

    Explicit close when perform() is done is forced with
    CURLOPT_FORBID_REUSE.

    And yes, libcurl _does_ close the connections in cleanup().

     
  • Evgeny Sabelsky

    Evgeny Sabelsky - 2005-12-09

    Logged In: YES
    user_id=738516

    FYI, CURLOPT_FORBID_REUSE fixed the problem.
    think need to investigate it or document this solution for
    application with persistent curl handle.

     
  • Daniel Stenberg

    Daniel Stenberg - 2005-12-12
    • status: open --> closed-works-for-me