Have a Go binary implement an http server:
package main
import (
\"net/http\"
)
func main() {
http.ListenAndServe(\":8080\", nil)
}
I
From the heap pprof
you have provided in comments, it looks like you are leaking memory via gorilla/sessions
and gorilla/context
(almost 400MB).
Refer to this ML thread: https://groups.google.com/forum/#!msg/gorilla-web/clJfCzenuWY/N_Xj9-5Lk6wJ and this GH issue: https://github.com/gorilla/sessions/issues/15
Here is a version that leaks extremely quickly:
package main
import (
"fmt"
// "github.com/gorilla/context"
"github.com/gorilla/sessions"
"net/http"
)
var (
cookieStore = sessions.NewCookieStore([]byte("cookie-secret"))
)
func main() {
http.HandleFunc("/", defaultHandler)
http.ListenAndServe(":8080", nil)
}
func defaultHandler(w http.ResponseWriter, r *http.Request) {
cookieStore.Get(r, "leak-test")
fmt.Fprint(w, "Hi there")
}
Here is one that cleans up and has a relatively static RSS:
package main
import (
"fmt"
"github.com/gorilla/context"
"github.com/gorilla/sessions"
"net/http"
)
var (
cookieStore = sessions.NewCookieStore([]byte("cookie-secret"))
)
func main() {
http.HandleFunc("/", defaultHandler)
http.ListenAndServe(":8080", context.ClearHandler(http.DefaultServeMux))
}
func defaultHandler(w http.ResponseWriter, r *http.Request) {
cookieStore.Get(r, "leak-test")
fmt.Fprint(w, "Hi there")
}