Closed
Description
What version of Go are you using (go version
)?
go1.11.1
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
- amd64
- darwin
- MacOS High Sierra (10.3.6)
What did you do?
The error too many open files is being thrown by submitting 20 requests per second in the code below.
The limit of open files on my system is 256 ( ulimit -n ).
Using lsof -p the FD is growing and not released.
If the OS open files limit is incremented the problem just is postponed. And I think that increment is not the solution.
package main
import (
"log"
"net/http"
"golang.org/x/crypto/bcrypt"
)
func main() {
srv := &http.Server{
Addr: ":9000",
}
http.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) {
log.Printf("/auth")
if err := bcrypt.CompareHashAndPassword([]byte("$2y$10$MWTmFsLIM3jHVNiDDZH/U.qkpebJ/z02phdclx9rEcz5B7/cbujcy"), []byte("test")); err != nil {
log.Printf("Error on check key and secret. (%v)", err.Error())
w.WriteHeader(http.StatusUnauthorized)
return
}
w.WriteHeader(http.StatusOK)
})
log.Printf("Listening on port 9000")
log.Fatal(srv.ListenAndServe())
}
What did you expect to see?
The FD be released and not throw too many open files error.
What did you see instead?
http: Accept error: accept tcp [::]:9000: accept: too many open files.