Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

struct context maybe cause memory leak? #46

Open
u0x01 opened this issue Jul 11, 2018 · 1 comment
Open

struct context maybe cause memory leak? #46

u0x01 opened this issue Jul 11, 2018 · 1 comment

Comments

@u0x01
Copy link

u0x01 commented Jul 11, 2018

memory leak in this case:

   24.51MB  1.77% 20.68%   327.24MB 23.58%  net/http.readRequest
  258.23MB 18.61% 39.29%   283.23MB 20.41%  net/textproto.(*Reader).ReadMIMEHeader

leak

see more: https://github.com/gorilla/sessions
see more: https://pathbox.github.io/2017/05/27/find-the-reason-memory-leak/

Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with 
context.ClearHandler or else you will leak memory! An easy way to do this is to wrap the top-level mux when calling http.ListenAndServe:

http.ListenAndServe(":8080", context.ClearHandler(http.DefaultServeMux))
The ClearHandler function is provided by the gorilla/context package.

More examples are available on the Gorilla website.
@lunny
Copy link
Owner

lunny commented Nov 2, 2018

Could you give more testing details?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants