I'm somewhat surprised in how many ways it's failing. I've tried to
simplify it, and the following sadly isn't as diverse in its error
messages.
Here's the simplified version:
package main
import (
"fmt"
"log"
"net/http"
"sync"
"testing"
"time"
)
func TestProvoke(t *testing.T) {
go func() {
log.Fatal(http.ListenAndServe(":7000", http.HandlerFunc(func(out
http.ResponseWriter, in *http.Request) {
out.Write([]byte("Hi"))
})))
}()
time.Sleep(500 * time.Millisecond)
var wg sync.WaitGroup
wg.Add(256)
for i := 0; i < 256; i++ {
go func() {
for j := 0; j < 400; j++ {
resp, err := http.Get("http://localhost:7000")
if err != nil {
panic(err)
}
resp.Body.Close()
}
wg.Done()
}()
}
wg.Wait()
}
It produces three error messages on OSX:
panic: Get http://localhost:7000: dial tcp 127.0.0.1:7000: connection
reset by peer
panic: Get http://localhost:7000: lookup localhost: no such host
panic: Get http://localhost:7000: dial tcp 127.0.0.1:7000: too many
open files
The last of which actually makes sense, and can be avoided by `ulimit -n
10000`
The first might also make sense if I'm just overloading the server.
However, the server doesn't give any log output indicating this. The middle
one just seems nuts to me.
The original snippet was more interesting. It produced all of the previous,
but also, after hundreds of successful runs:
panic: dial tcp 127.0.0.1:9000: can't assign requested address
After running the original snippet, I usually can't open pages in the web
browser for a few seconds after, as if I'm running out of sockets, file
handles, or something of the sort.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.