25

I received the following error on Apache bench:

apr_socket_connect(): Invalid argument (22)

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

kurious
  • 811
  • 7
  • 7

1 Answers1

46

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

kurious
  • 811
  • 7
  • 7
  • 1
    Using `127.0.0.1` also fixes this same issue on Window 7 64 bit pro, just tried it here. Thanks – NiCk Newman Feb 07 '16 at 21:06
  • 4
    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 09:40
  • localhost used to work for me, not sure why it stopped working. 127.0.0.1 resolved it. Thanks. – aled Nov 06 '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