Open spksoft opened 1 year ago
Thanks for the detailed issue. Can you please provide more details on the Keyfunc
you're passing to ParseWithClaims
. Is it as you have written it as a config.secret
, or is there a more involved implementation?
Also, are you using custom claims and embedding those provided by this package?
Ideally, I'd like to reproduce this locally to mimic your environment as much as possible.
@mfridman Sorry for late replying from your question KeyFunc is just a simple function
_, err := jwt.ParseWithClaims(bpJWT, bpClaims, func(token *jwt.Token) (interface{}, error) {
return config.Secret, nil
})
Now, I already solve this problem. Let's me explain it. In my case I used this as internal service that will received the jwt token from other internal service so when it used it internal decided to ignore error when secret is invalid. So when I fix it by update the secret to correct secret the memory did not leak. But, I still have a question why when I ParseWithClaims
and ignore the error it will got memory leak. You can reproduce by heavy call ParseWithClaims
function with invalid secret you will found the heap memory leak on pprof report.
You can reproduce by heavy call ParseWithClaims function with invalid secret you will found the heap memory leak on pprof report.
Thank you for those details. We've recently refactored the project, so I'd like to investigate the v5.0.0-rc.1 release
Is ParseWithClaims function make a memory leak ?
I use
golang-jwt/jwt/v4@v4.4.3
to parse jwt string to struct by ParseWithClaims. Our service have1350 req/sec
at peak time. So I monitoring the pods memory and visualize its by grafana see belowAfter that I dump the
heap profiling
from our services and visualize its bygo tool pprof
and selected the sample toinuse_space
. Pls See belowGraph view
Source View
Peak View
My implemented code. See below