I received the following error on Apache bench:

apr_socket_connect(): Invalid argument (22)

when trying to connect to http://localhost:9202.


On OSX, the fix is to use "" instead of localhost. Not sure why, but that prevents the error.

  • 1
    Using also fixes this same issue on Window 7 64 bit pro, just tried it here. Thanks – NiCk Newman Feb 7 '16 at 21:06
  • 3
    I would guess it is because localhost resolves to the local IPv6 address, and the server you're trying to connect to only listens on IPv4. (Actually, I'll add that to your answer!) – kqr Nov 23 '18 at 9:40
  • localhost used to work for me, not sure why it stopped working. resolved it. Thanks. – aled Nov 6 '19 at 17:11
  • @kqr that's a great guess. Is there a verbose option or something I could use to confirm that? Maybe capture the request with tcpdump? – Max Coplan Apr 24 '20 at 18:39
  • 1
    Confirmed by running ab -n 1 -c 1 http://localhost/api/users/ and sudo tcpdump ip6 and port 80 -i lo0 -X simultaneously. Thanks :) – Max Coplan Apr 24 '20 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.