curl-library
Re: Query regarding multiple easy handles on same socket
Date: Wed, 19 Jul 2017 12:33:05 -0700
Hi daniel,
Thanks for the reply. Please find more details inline.
On Wed, Jul 19, 2017 at 10:42 AM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Tue, 18 Jul 2017, srinivasa srikanth podila via curl-library wrote:
>
> I am doing it on scale of 10000 requests over 1000 connections with a HTTP
>> Get of 200kb.txt. Upon the socket close[connection reset] by Server, i see
>> a delayed POLL_REMOVE notification for some sockfds from libcurl and the
>> libuv is aborting due to BAD_FILE_DESCRIPTOR for those invalidated sockfd
>> by libcurl.
>>
>> Could you please let me know the ideal way of handling these erroneous
>> scenarios in my application?
>>
>
> I don't understand the error you're talking about. Can you elaborate on
> this delayed notifiction, what it is and how it happens when what is going
> on on the TCP connection?
I got to use multiple CURL multi handles in my async-application[Single
threaded]. I am sending HTTP GET of size 500mb using easy handles on all
multi-handles. As part of curl_socket_cb, I get [curl_socket_t] socket_fd
and I started Polling on it using uv_poll_start accordingly.
Now while the transfer is in progress, Server sends a FIN causing a sudden
abort of TCP connection. Looks like socket_fd is getting invalidated [as
BAD_FD] after Tcp connection termination. As my application has not
receiving any notification about sockfd invalidation, the lib_uv_poll which
keeps polling on that socket fd aborted my application with errorno:9 as
BAD_SOCKET_FD.
The way libcurl internally manages socket fd is good, however it is
application has to POLL on it. If there is a way that libcurl notifies
application on close(socket_fd), we could remove the poll on it
immediately. Please let me know if i am missing anything.
> I tried using CURLOPT_OPENSOCKETFUNCTION and CURLOPT_CLOSESOCKETFUNCTION to
>> maintain sockets manually using the multi-handle. However i am getting
>> close_socket notification for every single request, and i cannot close the
>> socket as there could be other easy handles using the same socket, So i am
>> unable to figure out a way to use multiple-requests over the same socket .
>>
>
> This also confuses me. When libcurl calls the open socket callback it
> needs a new socket and when it calls the close socket one the socket is not
> used by libcurl anymore. So yes, you can indeed close it. (And without the
> callbacks libcurl will of course do that by itself instead.)
>
> libcurl will not close a socket that is associated with a connection that
> it can and intend to reuse. It will only close sockets/connections when
> they can't be reused anymore.
Thanks for the explanation daniel, Could you please let me know the
libcurl behavior, if the connection is closed by server?
Also, I opened a single socket and attached 20 easy handles to the
multi-handles at once, After i see the 1st easy handle completes, i am
seeing a close_socket_cb for it though there are 19 more pending easy
handles. Actually application specifies the same socket is going to be used
by the pending easy_handles, still i get a close_socket notification for it.
Please update me if i am missing anything.
>
>
> I feel if there is a way that libcurl notifies application with
>> POLL_REMOVE when the sockfd is active, it would be great.
>>
>
> POLL_REMOVE to the application doesn't mean that the socket gets closed.
> It means that the application can stop monitoring the socket (for now).
> --
>
> / daniel.haxx.se
>
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-07-19