I am creating a system which is a http server in golang that will perform several request to another API based in every request that come to it.

e.g

curl localhost:8080/users?ids=1,2,3,4

will perform several concurrent gets to:

api.com/user/1

api.com/user/2

api.com/user/3

api.com/user/4

I am having a problem, the http.Client is getting my a panic, when it has a heavy concurrent requests (if I hit localhost:8080/users?ids=1,2,3,4.....40 with AB with 4 concurrent, or hitting refresh in my browser)

The proglem appears to be with the sentence (line 159)

resp, _ := client.Do(req)

My code is here (Not so large... 180 lines): http://play.golang.org/p/olibNz2n1Z

The panic error is this one:

goroutine 5 [select]:
net/http.(*persistConn).roundTrip(0xc210058f80, 0xc21000a720, 0xc210058f80, 0x0, 0x0)
    /usr/local/go/src/pkg/net/http/transport.go:879 +0x6d6
net/http.(*Transport).RoundTrip(0xc210058280, 0xc21005b1a0, 0x1, 0x0, 0x0)
    /usr/local/go/src/pkg/net/http/transport.go:187 +0x391
net/http.send(0xc21005b1a0, 0x590290, 0xc210058280, 0x0, 0x0, ...)
    /usr/local/go/src/pkg/net/http/client.go:168 +0x37f
net/http.(*Client).send(0xc21001e960, 0xc21005b1a0, 0x28, 0xc21001ec30, 0xc21005f570)
    /usr/local/go/src/pkg/net/http/client.go:100 +0xd9
net/http.(*Client).doFollowingRedirects(0xc21001e960, 0xc21005b1a0, 0x2ab298, 0x0, 0x0, ...)
    /usr/local/go/src/pkg/net/http/client.go:294 +0x671
net/http.(*Client).Do(0xc21001e960, 0xc21005b1a0, 0xa, 0x0, 0x0)
    /usr/local/go/src/pkg/net/http/client.go:129 +0x8f
main.buscarRecurso(0xc21000a650, 0xb, 0xc2100526c0)
    /Users/fscasserra/Documents/workspace/Luna/multiget-api/multiget.go:159 +0x131
created by main.obtenerRecursos
    /Users/fscasserra/Documents/workspace/Luna/multiget-api/multiget.go:106 +0x197

Can anyone help me?

Best regards, Fer