ibc / AsyncEngine

Ruby asynchronous event driven framework on top of libuv
6 stars 1 forks source link

uv_close(TCP handle) does not invoke connect_cb(error) #22

Closed ibc closed 12 years ago

ibc commented 12 years ago
  AE.run do
    # A socket that will be in connecting state for long...
    tcp = AE::TCPSocket.new "1.2.3.4", 9999

    # Close the socket after 2 seconds:
    AE.add_timer(2) { puts tcp.close }

    # We expect that uv_connect_cb(status=error) should happen right now, but NOT !!!
    # It will happen in next event of the loop (if there are...), so for example:
    AE.add_timer(5) { puts "now TCP on_connect_cb() is called with error !!!" }
  end

Not serious... it happens that the timer(2 seconds) closes the connecting TCP socket (uv_close()) so the uv_connect_cb(status=error) should be called. But it is not, and instead, the TCP socket UV close callback is called when a new event occurs (in this case then the second timer(5 seconds) fires), so we get the uv_connect_cb(status=error) after 5 seconds !!!

Reported in libuv: https://github.com/joyent/libuv/issues/448

ibc commented 12 years ago

Reproduced in C: https://gist.github.com/2880865

ibc commented 12 years ago

Fixed in libuv: https://github.com/joyent/libuv/commit/dea45940cd9436c27cba273535aabbcf86fd27d1