Hi Stefano,

Thanks for digging this out yourself, and for sharing your findings with us.

- Bert

On Tuesday, November 8, 2016 at 8:59:08 AM UTC-8, Stefano Cristiano wrote:
>
> Hi,
>
> My library is wrapping Libuv UDP to bind to some port, set broadcast to 
> true and send some data.
> Randomly my close() function (that is in turn calling uv_close) is 
> blocking to something slightly smaller than 1000 ms.
>
> The small piece of code extracted from my project is the following, even 
> if of course it's not straight uv code but should be relatively easy to 
> understand.
> The first function creates, binds, and sends the data on UDP, and the 
> later is the callback called when the write is done.
> After the write is done I would like to dispose the UDP socket of course, 
> and I am doing it after 100 ms from the write done callback.
>
>  void internalSend(bool broadcast, rrNode::stringView listen, int 
> listenOnPort,
>  rrNode::stringView whereToSend, int whereToConnect, rrNode::buffer buf) 
> { 
>
>   using namespace rrNode; 
>   udp client = udp::create(); 
>   client.bind(listen, listenOnPort); 
>   client.setBroadcast(broadcast); 
>   logINFO("Client.send"); 
>   client.send(buf, 0, buf.length(), whereToConnect, whereToSend, 
> bindMemLast(&this_class::writeDone, this, client)); 
>   clients.push_back(client); 
>
> } 
>
> void writeDone(rrNode::error /*err*/, rrNode::udp client)
> { 
>
>   using namespace rrNode; 
>   container::removeFirst(clients, client); 
>   timer t = setTimeout(100); 
>   t = [client]()mutable{client.close(); }; 
>   logINFO("Client.writeDone"); 
> }
>
> Debugger shows that *closesocket* function call (on Windows) is randomly 
> blocking for the above mentioned milliseconds (between 900 and 1000)
>
>
> void uv_udp_close(uv_loop_t* loop, uv_udp_t* handle) {
> uv_udp_recv_stop(handle);
> closesocket(handle->socket);
> handle->socket = INVALID_SOCKET;
> uv__handle_closing(handle);
> if (handle->reqs_pending == 0) {
> uv_want_endgame(loop, (uv_handle_t*) handle);
> }
> }
>
>
> Is this an intended behaviour or do you think that I could have been 
> hitting a bug in libuv?
>
> The closesocket documentation says that one should use the SO_LINGER 
> sockopt to control behaviour on close
>
>
> https://msdn.microsoft.com/en-us/library/windows/desktop/ms737582(v=vs.85).aspx
>
> I've tried without success to change the SO_LINGER sockopt.
>
> Any hints?
>
> Reason for this post is that I would like some feedback from the library 
> masters to understand if I'm hitting expected/known behaviour or not.
> If this doesn't look right I will be spending some time building a repro 
> in pure libuv.
>
> Thanks!
>

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to