Skip to content

ExtUv (libuv) does not report connection refused situation #188

Closed

Description

@Logioniz

I have preinstalled libev.

Imagine that port 12345 is not listening.
I took the http client code from example and try to connect to port 12345. I got an error right away:

Connection to tcp://127.0.0.1:12345 failed: Connection refused

Looks like evrything okey.

After that i installed libuv (uv-beta) and ran the same code. After 60sec i got en error:

Connection to 127.0.0.1:12345 timed out after 60 seconds

I ran strace and this is his short output is:

...
epoll_create1(EPOLL_CLOEXEC)            = 3
...
socket(AF_INET, SOCK_STREAM, IPPROTO_IP) = 9
fcntl(9, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(9, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
connect(9, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
...
epoll_ctl(3, EPOLL_CTL_ADD, 9, {EPOLLIN, {u32=4294967295, u64=18446744073709551615}}) = 0
epoll_ctl(3, EPOLL_CTL_DEL, 9, 0x7ffcf580163c) = 0
ioctl(9, FIONBIO, [1])                  = 0
epoll_ctl(3, EPOLL_CTL_DEL, 9, 0x7ffcf580169c) = -1 ENOENT (No such file or directory)
...
epoll_ctl(3, EPOLL_CTL_ADD, 6, {EPOLLIN, {u32=6, u64=6}}) = 0
epoll_ctl(3, EPOLL_CTL_ADD, 8, {EPOLLIN, {u32=8, u64=8}}) = 0
epoll_ctl(3, EPOLL_CTL_ADD, 9, {EPOLLOUT, {u32=9, u64=9}}) = 0
epoll_wait(3, [{EPOLLOUT|EPOLLERR|EPOLLHUP, {u32=9, u64=9}}], 1024, 59982) = 1
epoll_wait(3, [{EPOLLOUT|EPOLLERR|EPOLLHUP, {u32=9, u64=9}}], 1024, 59982) = 1
epoll_ctl(3, EPOLL_CTL_DEL, 9, 0x7ffcf57fe6a0) = 0
epoll_wait(3, strace: Process 8843 detached
 <detached ...>

It looks like that 9th descriptor (client socket) is not in event loop.
I can't found where desriptor 6th was initialized.
And i don't know what is 8th descriptor which was created by eventfd2 system call (i also have preinstalled eio).

Link to full strace.
Link to test source code.

Also it would nice to have ability to set custom event loop in Factory class manually:
Factory::create() - this is default
Factory::create('uv')
Factory::create('ev')
Factory::create('event')
...

Activity

  1. clue commented on Apr 10, 2019

    @clue
    Member

    @Logioniz Interesting find, thanks for reporting this!

    Can you try to reproduce this by running the examples, in particular https://github.com/reactphp/event-loop/blob/a0ecac955c67b57c40fe4a1b88a7cca1b58c982d/examples/14-http-client-async.php? This should use the same connection logic and highlights how the EventLoop is involved with detecting a writable event without relying on any external components.

  2. Logioniz commented on Apr 10, 2019

    @Logioniz
    Author

    @clue this example works good, because google always available.
    But if i change two lines of code:

    $ip = '127.0.0.1';
    ...
    $stream = stream_socket_client('tcp://' . $ip . ':12345', $errno, $errstr, null, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
    

    current problem appears (using uv of course).

    By the way strace similar to strace in description of this topic, but in the end we have infinity number of lines (due to using periodicTimer):

    epoll_wait(3, [], 1024, 11)             = 0
    write(1, ".", 1.)                        = 1
    epoll_wait(3, [], 1024, 11)             = 0
    write(1, ".", 1.)                        = 1
    epoll_wait(3, [], 1024, 11)             = 0
    
  3. WyriHaximus commented on Apr 10, 2019

    @WyriHaximus
    Member

    I'll look into this, might have an idea what is causing this

    Also it would nice to have ability to set custom event loop in Factory class manually:
    Factory::create() - this is default
    Factory::create('uv')
    Factory::create('ev')
    Factory::create('event')
    ...

    The factory is essentially an easy to use way to always get the most performant loop. If you want to use a specific look instantiate that loop directly instead of using the factory.

  4. changed the title [-]Libuv problem[/-] [+]ExtUv (libuv) does not report connection refused situation[/+] on Apr 26, 2019
  5. added this to the v1.1.1 milestone on Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions