• ab fails to connect to localhost


    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 127.0.0.1:8000/
    
    In /etc/hosts I have:
    
    127.0.0.1   localhost.localdomain   localhost
    ::1     localhost.localdomain   localhost
    
    The issue here is caused by ab taking the first result returned by apr_sockaddr_info_get:
    
    https://github.com/apache/httpd/blob/2.4.29/support/ab.c#L1835-L1837
    
    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, mp);
        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) {
                continue;
            } else if (rv == APR_SUCCESS) {
                break;
            } 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
    
    https://gist.github.com/x-yuri/5ad28ac0a22ca19a7c3073ce0de5abf0
    https://gist.github.com/x-yuri/95fd4776fb9bf8f1eaae7eb2e7ed6bd4
    

      

  • 相关阅读:
    菜鸟攻城狮4(基本语法)
    Spring 3.x 企业引用开发实战(陈雄华/林开雄)
    进击的菜鸟问题1(设置checkbox全选)
    Maven实战
    菜鸟攻城狮3(Holle World)
    菜鸟攻城狮2(JAVA开发环境)
    git基本使用
    跨域问题及解决跨域的方案
    原生ajax相关概念
    php服务器语言,MySQL数据库以及php怎么操作数据库
  • 原文地址:https://www.cnblogs.com/jack-Star/p/9951428.html
Copyright © 2020-2023  润新知