So, I've got the following snippet:$ cat testserver.go
package main
import (
"net/http"
"io"
"strconv"
)
func HelloServer(c http.ResponseWriter, req *http.Request) {
result := "hello, world!\n"
c.Header().Set("Content-Type", "text/plain")
c.Header().Set("Content-Length", strconv.Itoa(len(result)))
io.WriteString(c, result);req.Body.Close()
}
func main() {
http.Handle("/", http.HandlerFunc(HelloServer))
http.ListenAndServe(":8080", nil)
}
$ go build testserver.go
$ netstat -an | grep TIME | wc -l
0
$ curl -s http://localhost:8080/
hello, world!
$ netstat -an | grep TIME | wc -l
1However, every time a connection is made, the socket ends up in TIME_WAIT. It looks like the socket is not closed on the go side.Am I missing something to have these sockets closed once a request is finished?Yes, keep-alive, blah blah blah, but once a connection drops, how do I close the socket on the server side?I see this with go1.0.3 as well as tip (16294:43eb97ed849a). Thoughts?-T.--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Imho, this is TCP by design. You'll just have to wait out the timeout period till the TCP stack gives back the port to the OS. Or you can restart the network stack :P