Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http/httptest: "socket is not connected" error after starting httptest.NewServer #9430

Closed
hannesr0 opened this issue Dec 23, 2014 · 7 comments

Comments

@hannesr0
Copy link

https://gist.github.com/hannesroth/dd9871ca6275fcb435aa

ok proof 0.241s
DONE
ok proof 0.312s
DONE
ok proof 0.419s
DONE
--- FAIL: Test559-8 (0.00s)
proof_test.go:4037: write tcp 127.0.0.1:63671: socket is not connected

go version go1.4 darwin/amd64
Darwin ... 14.0.0 Darwin Kernel Version 14.0.0

We found this when running lots of tests in parallel against our server implementation on our Mac machines. We are unable to reproduce it on a Linux (3.2.51, x86_64) machine.

@bradfitz
Copy link
Contributor

Probably running out of ephemeral ports or hitting fd limit.

@hannesr0
Copy link
Author

@bradfitz:

If I run it with -cpu 32 -parallel 1024 it will print this after a while:
proof_test.go:4037: dial tcp 127.0.0.1:50697: can't assign requested address

If I change my ulimit -n 100, and run it with -cpu 8 -parallel 1024, I get this:
panic: httptest: failed to listen on a port: listen tcp6 [::1]:0: too many open files [recovered]

So I think this is a different error.

@bradfitz
Copy link
Contributor

cc @mikioh who likes stuff like this.

@mikioh mikioh changed the title "socket is not connected" error after starting httptest.NewServer net/http/httptest: "socket is not connected" error after starting httptest.NewServer Dec 28, 2014
@shendongming
Copy link

test-web.go

package main

import "github.com/go-martini/martini"
import "runtime"
import (
    "log"
)

func main() {
    n := runtime.NumCPU()
    log.Println("CPU:", n)
    runtime.GOMAXPROCS(n)

    m := martini.Classic()
    m.Get("/", func() string {
        return "Hello world!"
    })
    m.Run()
}

boom -cpus 8 -n 10000 -c 240 http://127.0.0.1:3000/
10000 / 10000 Booooooooooooooooooooooooooooooooooooooooooooooooooooooo! 100.00 %

Summary:
Total: 6.0928 secs.
Slowest: 3.5828 secs.
Fastest: 0.0006 secs.
Average: 0.0413 secs.
Requests/sec: 1472.8877
Total Data Received: 107688 bytes.
Response Size per Request: 12 bytes.

Status code distribution:
[200] 8974 responses

Response time histogram:
0.001 [1] |
0.359 [8885] |∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
0.717 [3] |
1.075 [16] |
1.433 [10] |
1.792 [1] |
2.150 [7] |
2.508 [6] |
2.866 [6] |
3.225 [0] |
3.583 [39] |

Latency distribution:
10% in 0.0074 secs.
25% in 0.0096 secs.
50% in 0.0126 secs.
75% in 0.0221 secs.
90% in 0.0380 secs.
95% in 0.0477 secs.
99% in 0.2838 secs.

Error distribution:
[2] Get http://127.0.0.1:3000/: write tcp 127.0.0.1:3000: socket is not connected
[841] Get http://127.0.0.1:3000/: dial tcp 127.0.0.1:3000: can't assign requested address
[183] Get http://127.0.0.1:3000/: read tcp 127.0.0.1:3000: connection reset by peer

@elmacnifico
Copy link

@hannesroth macs have a reduced number of ephemeral port try

 sudo sysctl -w net.inet.ip.portrange.first=32768

This fixes your example for me.

@elmacnifico
Copy link

Reason is the min lifetime of a port on mac os plus the available number of ports, which is bound to run out.

@rsc rsc removed the os-macosx label Apr 10, 2015
@rsc rsc added this to the Go1.5Maybe milestone Apr 10, 2015
@rsc rsc added OS-Darwin and removed repo-main labels Apr 14, 2015
@bradfitz
Copy link
Contributor

Timeout. And I don't think there's anything actionable here.

We can reopen if anybody disagrees.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants