Apache Bench test error on OS X: "apr_socket_recv: Connection reset by peer (54)"

I updated my MacBook Pro 13" to Lion a few weeks ago. I just found out that Apache Bench (apache2.2.19) is not working. It always shows this error, no matter what:

apr_socket_recv: Connection reset by peer (54)

I also did a clean install on my Mac Mini and it produced the same error.

How can I fix this?


Solution 1:

Note that if you use -r with Apache Bench, it won't exit on errors.

From the documentation:

-r
Don't exit on socket receive errors.

Solution 2:

This is due to a bug in the Apache software that's bundled with Lion. A more recent version of Apache (beta) fixes the problem. To fix ab, here are the steps:

  1. Download the latest version of Apache

    $ wget http://apache.mirrors.pair.com//httpd/httpd-2.3.16-beta.tar.bz2
    

If 2.3.16 is not available, go to http://apache.mirrors.pair.com/httpd and get the latest

  1. Install pcre (you need brew for this)

    $ brew install pcre
    
  2. Build Apache

    $ tar xzvf httpd-2.3.16-beta.tar.bz2
    $ cd httpd-2.3.16-beta
    $ ./configure
    $ make
    
  3. Overwrite the existing ab with the newly built one

    $ sudo cp support/ab /usr/sbin
    

Solution 3:

Using the method of updating ab through homebrew at this link worked for me.

brew install 'https://raw.github.com/simonair/homebrew-dupes/e5177ef4fc82ae5246842e5a544124722c9e975b/ab.rb'
brew test ab

Solution 4:

Did you try using: 127.0.0.1 instead of localhost?

Also my ab fails if I don't write url with http:// in front.

Solution 5:

I had the same error with Mountain Lion ab v2.3, and was almost ready to install brew and the latest version of ab as instructed by one of the above answers. Before finally going that way I tried just adding the trailing slash.

user$ ab http://dl.cubrid.org
ab: invalid URL
Usage: ab [options] [http[s]://]hostname[:port]/path

In the above message pay attention to the required format of the input URL. Optional components are marked with square brackets, but notice that /path part seems to be not optional. So I assumed that if I'm testing the root domain, I should at least add the trailing slash, which really did the trick! I hope this helps to you, too.

user$ ab dl.cubrid.org/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking dl.cubrid.org (be patient).....done


Server Software:        
Server Hostname:        dl.cubrid.org
Server Port:            80

Document Path:          /
Document Length:        13437 bytes

Concurrency Level:      1
Time taken for tests:   0.863 seconds
Complete requests:      1
Failed requests:        0
Write errors:           0
Total transferred:      13606 bytes
HTML transferred:       13437 bytes
Requests per second:    1.16 [#/sec] (mean)
Time per request:       862.778 [ms] (mean)
Time per request:       862.778 [ms] (mean, across all concurrent requests)
Transfer rate:          15.40 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      207  207   0.0    207     207
Processing:   655  655   0.0    655     655
Waiting:      234  234   0.0    234     234
Total:        862  862   0.0    862     862