[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug 61968] New: ab fails to connect to localhost (111)


            Bug ID: 61968
           Summary: ab fails to connect to localhost (111)
           Product: Apache httpd-2
           Version: 2.4.29
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core
          Assignee: bugs@xxxxxxxxxxxxxxxx
          Reporter: yuri.kanivetsky@xxxxxxxxx
  Target Milestone: ---

The following command fails:

$ ab -n 1 localhost:8000/
Benchmarking localhost (be patient)...apr_socket_recv: Connection refused (111)

But this one succeeds:

$ ab -n 1

In /etc/hosts I have:   localhost.localdomain   localhost
::1     localhost.localdomain   localhost

The issue here is caused by ab taking the first result returned by


But apr_sockaddr_info_get returns a list. If it were to try the second sockaddr
structure, it would connect. This way it works:

    rv = apr_sockaddr_info_get(&sa, REMOTE_HOST, APR_UNSPEC, REMOTE_PORT, 0,
    if (rv != APR_SUCCESS) {
        return rv;

    for ( ; sa; sa = sa->next) {
        rv = apr_socket_create(&s, sa->family, SOCK_STREAM, APR_PROTO_TCP, mp);
        if (rv != APR_SUCCESS) {
            return rv;

        apr_socket_opt_set(s, APR_SO_NONBLOCK, 1);
        apr_socket_timeout_set(s, SOCK_TIMEOUT);

        rv = apr_socket_connect(s, sa);
        if (rv == ECONNREFUSED) {
        } else if (rv == APR_SUCCESS) {
        } else {
            return rv;

    apr_socket_opt_set(s, APR_SO_NONBLOCK, 0);
    apr_socket_timeout_set(s, SOCK_TIMEOUT);

Other tools (like, curl, wget, w3m) deal with it just fine.

P.S. A couple of links just in case


You are receiving this mail because:
You are the assignee for the bug.
To unsubscribe, e-mail: bugs-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: bugs-help@xxxxxxxxxxxxxxxx