Go http标准库中的内存泄漏?

Go http标准库中的内存泄漏?,第1张

Go http标准库中的内存泄漏

pprof
您在注释中提供的堆中,看来您正在通过
gorilla/sessions
gorilla/context
(将近400MB)泄漏内存。

请参阅以下ML线程:[https](https://groups.google.com/forum/#!msg/gorilla-
web/clJfCzenuWY/N_Xj9-5Lk6wJ) :
[//groups.google.com/forum/#!](https://groups.google.com/forum/#!msg/gorilla-
web/clJfCzenuWY/N_Xj9-5Lk6wJ) msg/gorilla-web/clJfCzenuWY/
[N_Xj9-5Lk6wJ](https://groups.google.com/forum/#!msg/gorilla-
web/clJfCzenuWY/N_Xj9-5Lk6wJ)和此GH问题:https
//github.com/gorilla/sessions/issues/
15

这是一个泄漏速度非常快的版本:

package mainimport (    "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")}

这是一个清理并具有相对静态的RSS的示例:

package mainimport (    "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")}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5086946.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-16
下一篇2022-11-16

发表评论

登录后才能评论

评论列表(0条)

    保存