Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is ParseWithClaims function make a memory leak ? #266

Open
spksoft opened this issue Jan 20, 2023 · 3 comments
Open

Is ParseWithClaims function make a memory leak ? #266

spksoft opened this issue Jan 20, 2023 · 3 comments

Comments

@spksoft
Copy link

spksoft commented Jan 20, 2023

Is ParseWithClaims function make a memory leak ?

I use golang-jwt/jwt/[email protected] to parse jwt string to struct by ParseWithClaims. Our service have 1350 req/sec at peak time. So I monitoring the pods memory and visualize its by grafana see below

1
image

After that I dump the heap profiling from our services and visualize its by go tool pprof and selected the sample to inuse_space. Pls See below

  1. Graph view
    2

  2. Source View

github.com/golang-jwt/jwt/v4.(*Parser).ParseWithClaims
/go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/parser.go

  Total:    217.01MB   217.01MB (flat, cum) 98.63%
     80            .          .           ??? 
     88     217.01MB   217.01MB           ??? 
     92            .          .           ??? 
    106            .          .           ??? 
net/http.newBufioReader
/usr/local/go/src/net/http/server.go

  Total:         1MB        1MB (flat, cum)  0.46%
    838            .          .           ??? 
    845          1MB        1MB           ??? 
net/http.(*conn).serve
/usr/local/go/src/net/http/server.go

  Total:           0        1MB (flat, cum)  0.46%
   1869            .          .           ??? 
   1873            .          .           ??? 
   1874            .        1MB           ??? 
   1875            .          .           ??? 
   1878            .          .           ??? 
net/http.(*conn).serve
/usr/local/go/src/net/http/server.go

  Total:           0   218.51MB (flat, cum) 99.31%
   1952            .   218.51MB           ??? 
   1957            .          .           ??? 
   1962            .          .           ??? 
net/http.serverHandler.ServeHTTP
/usr/local/go/src/net/http/server.go

  Total:           0   218.51MB (flat, cum) 99.31%
   2887            .   218.51MB           ??? 
bufio.NewReaderSize
/usr/local/go/src/bufio/bufio.go

  Total:         1MB        1MB (flat, cum)  0.46%
     56            .          .           ??? 
     57          1MB        1MB           ??? 
bufio.NewReader
/usr/local/go/src/bufio/bufio.go

  Total:         1MB        1MB (flat, cum)  0.46%
     63          1MB        1MB           ??? 
regexp/syntax.Compile
/usr/local/go/src/regexp/syntax/compile.go

  Total:           0   517.33kB (flat, cum)  0.23%
     73            .   517.33kB           ??? 
regexp/syntax.(*compiler).compile
/usr/local/go/src/regexp/syntax/compile.go

  Total:           0   517.33kB (flat, cum)  0.23%
    109            .   517.33kB           ??? 
regexp/syntax.(*compiler).compile
/usr/local/go/src/regexp/syntax/compile.go

  Total:           0     1.01MB (flat, cum)  0.46%
    132            .   517.33kB           ??? 
    146            .   517.33kB           ??? 
regexp/syntax.(*compiler).inst
/usr/local/go/src/regexp/syntax/compile.go

  Total:    517.33kB   517.33kB (flat, cum)  0.23%
    163     517.33kB   517.33kB           ??? 
regexp/syntax.(*compiler).rune
/usr/local/go/src/regexp/syntax/compile.go

  Total:    517.33kB   517.33kB (flat, cum)  0.23%
    257     517.33kB   517.33kB           ??? 
github.com/golang-jwt/jwt/v4.(*SigningMethodHMAC).Sign
/go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/hmac.go

  Total:    512.38kB   512.38kB (flat, cum)  0.23%
     88            .          .           ??? 
     89     512.38kB   512.38kB           ??? 
     91            .          .           ??? 
bytes.(*Buffer).grow
/usr/local/go/src/bytes/buffer.go

  Total:           0   512.25kB (flat, cum)  0.23%
    142            .   512.25kB           ??? 
bytes.(*Buffer).ReadFrom
/usr/local/go/src/bytes/buffer.go

  Total:           0   512.25kB (flat, cum)  0.23%
    202            .   512.25kB           ??? 
bytes.makeSlice
/usr/local/go/src/bytes/buffer.go

  Total:    512.25kB   512.25kB (flat, cum)  0.23%
    229     512.25kB   512.25kB           ??? 
reflect.mapiterinit
/usr/local/go/src/runtime/map.go

  Total:    512.05kB   512.05kB (flat, cum)  0.23%
   1339     512.05kB   512.05kB           ??? 
github.com/getsentry/sentry-go/gin.(*handler).handle
/go/pkg/mod/github.com/getsentry/[email protected]/gin/sentrygin.go

  Total:           0   218.01MB (flat, cum) 99.09%
     52            .          .           ??? 
     54            .          .           ??? 
     55            .          .           ??? 
     57            .   218.01MB           ??? 
<my_pkg>/logger/middlewares.NewRequestLogger.func1
/app/logger/middlewares/httplogger.go

  Total:           0   218.51MB (flat, cum) 99.31%
     22            .          .           ??? 
     23            .   512.25kB           ??? 
     25            .          .           ??? 
     31            .          .           ??? 
     34            .          .           ??? 
     36            .          .           ??? 
     37            .          .           ??? 
     38            .          .           ??? 
     41            .          .           ??? 
     42            .          .           ??? 
     43            .          .           ??? 
     46            .   218.01MB           ??? 
     50            .          .           ??? 
     51            .          .           ??? 
     59            .          .           ??? 
github.com/gin-gonic/gin.(*Engine).ServeHTTP
/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go

  Total:           0   218.51MB (flat, cum) 99.31%
    567            .          .           ??? 
    572            .   218.51MB           ??? 
    574            .          .           ??? 
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest
/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go

  Total:           0   218.51MB (flat, cum) 99.31%
    616            .   218.51MB           ??? 
    617            .          .           ??? 
regexp.Compile
/usr/local/go/src/regexp/regexp.go

  Total:           0   517.33kB (flat, cum)  0.23%
    133            .   517.33kB           ??? 
regexp.compile
/usr/local/go/src/regexp/regexp.go

  Total:           0   517.33kB (flat, cum)  0.23%
    178            .   517.33kB           ??? 
    189            .          .           ??? 
regexp.MustCompile
/usr/local/go/src/regexp/regexp.go

  Total:           0   517.33kB (flat, cum)  0.23%
    309            .   517.33kB           ??? 
  1. Peak View
      File: service
Type: inuse_space
Time: Jan 20, 2023 at 3:35pm (+07)
Showing nodes accounting for 220.02MB, 100% of 220.02MB total
----------------------------------------------------------+-------------
      flat  flat%   sum%        cum   cum%   calls calls% + context 	 	 
----------------------------------------------------------+-------------
                                          217.01MB   100% |   github.com/golang-jwt/jwt/v4.ParseWithClaims /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:108
  217.01MB 98.63% 98.63%   217.01MB 98.63%                | github.com/golang-jwt/jwt/v4.(*Parser).ParseWithClaims /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/parser.go:88
----------------------------------------------------------+-------------
                                               1MB   100% |   bufio.NewReader /usr/local/go/src/bufio/bufio.go:63 (inline)
       1MB  0.46% 99.09%        1MB  0.46%                | bufio.NewReaderSize /usr/local/go/src/bufio/bufio.go:57
----------------------------------------------------------+-------------
                                            0.51MB   100% |   regexp/syntax.(*compiler).rune /usr/local/go/src/regexp/syntax/compile.go:257 (inline)
    0.51MB  0.23% 99.32%     0.51MB  0.23%                | regexp/syntax.(*compiler).inst /usr/local/go/src/regexp/syntax/compile.go:163
----------------------------------------------------------+-------------
                                            0.50MB   100% |   github.com/golang-jwt/jwt/v4.(*Token).SignedString /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:64
    0.50MB  0.23% 99.55%     0.50MB  0.23%                | github.com/golang-jwt/jwt/v4.(*SigningMethodHMAC).Sign /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/hmac.go:89
----------------------------------------------------------+-------------
                                            0.50MB   100% |   bytes.(*Buffer).grow /usr/local/go/src/bytes/buffer.go:142
    0.50MB  0.23% 99.77%     0.50MB  0.23%                | bytes.makeSlice /usr/local/go/src/bytes/buffer.go:229
----------------------------------------------------------+-------------
                                            0.50MB   100% |   reflect.Value.MapKeys /usr/local/go/src/reflect/value.go:1215
    0.50MB  0.23%   100%     0.50MB  0.23%                | reflect.mapiterinit /usr/local/go/src/runtime/map.go:1339
----------------------------------------------------------+-------------
                                               1MB   100% |   net/http.newBufioReader /usr/local/go/src/net/http/server.go:845 (inline)
         0     0%   100%        1MB  0.46%                | bufio.NewReader /usr/local/go/src/bufio/bufio.go:63
                                               1MB   100% |   bufio.NewReaderSize /usr/local/go/src/bufio/bufio.go:57 (inline)
----------------------------------------------------------+-------------
                                            0.50MB   100% |   <my_pkg>/logger/middlewares.NewRequestLogger.func1 /app/logger/middlewares/httplogger.go:23
         0     0%   100%     0.50MB  0.23%                | bytes.(*Buffer).ReadFrom /usr/local/go/src/bytes/buffer.go:202
                                            0.50MB   100% |   bytes.(*Buffer).grow /usr/local/go/src/bytes/buffer.go:142
----------------------------------------------------------+-------------
                                            0.50MB   100% |   bytes.(*Buffer).ReadFrom /usr/local/go/src/bytes/buffer.go:202
         0     0%   100%     0.50MB  0.23%                | bytes.(*Buffer).grow /usr/local/go/src/bytes/buffer.go:142
                                            0.50MB   100% |   bytes.makeSlice /usr/local/go/src/bytes/buffer.go:229
----------------------------------------------------------+-------------
                                            0.50MB   100% |   encoding/json.Marshal /usr/local/go/src/encoding/json/encode.go:161
         0     0%   100%     0.50MB  0.23%                | encoding/json.(*encodeState).marshal /usr/local/go/src/encoding/json/encode.go:332
                                            0.50MB   100% |   encoding/json.(*encodeState).reflectValue /usr/local/go/src/encoding/json/encode.go:360
----------------------------------------------------------+-------------
                                            0.50MB   100% |   encoding/json.(*encodeState).marshal /usr/local/go/src/encoding/json/encode.go:332
         0     0%   100%     0.50MB  0.23%                | encoding/json.(*encodeState).reflectValue /usr/local/go/src/encoding/json/encode.go:360
                                            0.50MB   100% |   encoding/json.mapEncoder.encode /usr/local/go/src/encoding/json/encode.go:797
----------------------------------------------------------+-------------
                                            0.50MB   100% |   github.com/golang-jwt/jwt/v4.(*Token).SigningString /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:78
         0     0%   100%     0.50MB  0.23%                | encoding/json.Marshal /usr/local/go/src/encoding/json/encode.go:161
                                            0.50MB   100% |   encoding/json.(*encodeState).marshal /usr/local/go/src/encoding/json/encode.go:332
----------------------------------------------------------+-------------
                                            0.50MB   100% |   encoding/json.(*encodeState).reflectValue /usr/local/go/src/encoding/json/encode.go:360
         0     0%   100%     0.50MB  0.23%                | encoding/json.mapEncoder.encode /usr/local/go/src/encoding/json/encode.go:797
                                            0.50MB   100% |   reflect.Value.MapKeys /usr/local/go/src/reflect/value.go:1215
----------------------------------------------------------+-------------
                                          217.51MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173
         0     0%   100%   217.51MB 98.86%                | <my_pkg>/app/proxy.proxy.HandleRequestAndRedirect /app/app/proxy/handler.go:43
                                          217.01MB 99.77% |   <my_pkg>/app/proxy.proxy.<my_handler2> /app/app/proxy/handler.go:68
                                            0.50MB  0.23% |   <my_pkg>/app/proxy.proxy.<my_handler2> /app/app/proxy/handler.go:113
----------------------------------------------------------+-------------
                                            0.50MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173
         0     0%   100%     0.50MB  0.23%                | <my_pkg>/app/proxy.proxy.HandleRequestAndRedirect /app/app/proxy/handler.go:46
                                            0.50MB   100% |   <my_pkg>/app/proxy.proxy.<my_handler> /app/app/proxy/handler.go:172
----------------------------------------------------------+-------------
                                            0.50MB   100% |   <my_pkg>/app/proxy.proxy.HandleRequestAndRedirect /app/app/proxy/handler.go:46
         0     0%   100%     0.50MB  0.23%                | <my_pkg>/app/proxy.proxy.<my_handler> /app/app/proxy/handler.go:172
                                            0.50MB   100% |   github.com/golang-jwt/jwt/v4.(*Token).SignedString /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:61
----------------------------------------------------------+-------------
                                            0.50MB   100% |   <my_pkg>/app/proxy.proxy.HandleRequestAndRedirect /app/app/proxy/handler.go:43
         0     0%   100%     0.50MB  0.23%                | <my_pkg>/app/proxy.proxy.<my_handler2> /app/app/proxy/handler.go:113
                                            0.50MB   100% |   github.com/golang-jwt/jwt/v4.(*Token).SignedString /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:64
----------------------------------------------------------+-------------
                                          217.01MB   100% |   <my_pkg>/app/proxy.proxy.HandleRequestAndRedirect /app/app/proxy/handler.go:43
         0     0%   100%   217.01MB 98.63%                | <my_pkg>/app/proxy.proxy.<my_handler2> /app/app/proxy/handler.go:68
                                          217.01MB   100% |   github.com/golang-jwt/jwt/v4.ParseWithClaims /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:108
----------------------------------------------------------+-------------
                                          218.01MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173
         0     0%   100%   218.01MB 99.09%                | <my_pkg>/logger/middlewares.CaptureException /app/logger/middlewares/sentry.go:13
                                          218.01MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (inline)
----------------------------------------------------------+-------------
                                            0.50MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173
         0     0%   100%     0.50MB  0.23%                | <my_pkg>/logger/middlewares.NewRequestLogger.func1 /app/logger/middlewares/httplogger.go:23
                                            0.50MB   100% |   bytes.(*Buffer).ReadFrom /usr/local/go/src/bytes/buffer.go:202
----------------------------------------------------------+-------------
                                          218.01MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173
         0     0%   100%   218.01MB 99.09%                | <my_pkg>/logger/middlewares.NewRequestLogger.func1 /app/logger/middlewares/httplogger.go:46
                                          218.01MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (inline)
----------------------------------------------------------+-------------
                                          218.01MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173
         0     0%   100%   218.01MB 99.09%                | github.com/getsentry/sentry-go/gin.(*handler).handle /go/pkg/mod/github.com/getsentry/[email protected]/gin/sentrygin.go:57
                                          218.01MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (inline)
----------------------------------------------------------+-------------
                                          218.51MB   100% |   github.com/gin-gonic/gin.(*Engine).handleHTTPRequest /go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:616 (inline)
                                          218.01MB 99.77% |   <my_pkg>/logger/middlewares.CaptureException /app/logger/middlewares/sentry.go:13 (inline)
                                          218.01MB 99.77% |   <my_pkg>/logger/middlewares.NewRequestLogger.func1 /app/logger/middlewares/httplogger.go:46 (inline)
                                          218.01MB 99.77% |   github.com/getsentry/sentry-go/gin.(*handler).handle /go/pkg/mod/github.com/getsentry/[email protected]/gin/sentrygin.go:57 (inline)
         0     0%   100%   218.51MB 99.31%                | github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173
                                          218.01MB 99.77% |   <my_pkg>/logger/middlewares.CaptureException /app/logger/middlewares/sentry.go:13
                                          218.01MB 99.77% |   <my_pkg>/logger/middlewares.NewRequestLogger.func1 /app/logger/middlewares/httplogger.go:46
                                          218.01MB 99.77% |   github.com/getsentry/sentry-go/gin.(*handler).handle /go/pkg/mod/github.com/getsentry/[email protected]/gin/sentrygin.go:57
                                          217.51MB 99.54% |   <my_pkg>/app/proxy.proxy.HandleRequestAndRedirect /app/app/proxy/handler.go:43
                                            0.50MB  0.23% |   <my_pkg>/logger/middlewares.NewRequestLogger.func1 /app/logger/middlewares/httplogger.go:23
                                            0.50MB  0.23% |   <my_pkg>/app/proxy.proxy.HandleRequestAndRedirect /app/app/proxy/handler.go:46
----------------------------------------------------------+-------------
                                          218.51MB   100% |   net/http.serverHandler.ServeHTTP /usr/local/go/src/net/http/server.go:2887
         0     0%   100%   218.51MB 99.31%                | github.com/gin-gonic/gin.(*Engine).ServeHTTP /go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:572
                                          218.51MB   100% |   github.com/gin-gonic/gin.(*Engine).handleHTTPRequest /go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:616
----------------------------------------------------------+-------------
                                          218.51MB   100% |   github.com/gin-gonic/gin.(*Engine).ServeHTTP /go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:572
         0     0%   100%   218.51MB 99.31%                | github.com/gin-gonic/gin.(*Engine).handleHTTPRequest /go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:616
                                          218.51MB   100% |   github.com/gin-gonic/gin.(*Context).Next /go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:173 (inline)
----------------------------------------------------------+-------------
                                            0.51MB   100% |   runtime.doInit /usr/local/go/src/runtime/proc.go:6265
         0     0%   100%     0.51MB  0.23%                | github.com/go-playground/validator/v10.init /go/pkg/mod/github.com/go-playground/validator/[email protected]/regexes.go:68
                                            0.51MB   100% |   regexp.MustCompile /usr/local/go/src/regexp/regexp.go:309
----------------------------------------------------------+-------------
                                            0.50MB   100% |   <my_pkg>/app/proxy.proxy.<my_handler> /app/app/proxy/handler.go:172
         0     0%   100%     0.50MB  0.23%                | github.com/golang-jwt/jwt/v4.(*Token).SignedString /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:61
                                            0.50MB   100% |   github.com/golang-jwt/jwt/v4.(*Token).SigningString /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:78
----------------------------------------------------------+-------------
                                            0.50MB   100% |   <my_pkg>/app/proxy.proxy.<my_handler2> /app/app/proxy/handler.go:113
         0     0%   100%     0.50MB  0.23%                | github.com/golang-jwt/jwt/v4.(*Token).SignedString /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:64
                                            0.50MB   100% |   github.com/golang-jwt/jwt/v4.(*SigningMethodHMAC).Sign /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/hmac.go:89
----------------------------------------------------------+-------------
                                            0.50MB   100% |   github.com/golang-jwt/jwt/v4.(*Token).SignedString /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:61
         0     0%   100%     0.50MB  0.23%                | github.com/golang-jwt/jwt/v4.(*Token).SigningString /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:78
                                            0.50MB   100% |   encoding/json.Marshal /usr/local/go/src/encoding/json/encode.go:161
----------------------------------------------------------+-------------
                                          217.01MB   100% |   <my_pkg>/app/proxy.proxy.<my_handler2> /app/app/proxy/handler.go:68
         0     0%   100%   217.01MB 98.63%                | github.com/golang-jwt/jwt/v4.ParseWithClaims /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/token.go:108
                                          217.01MB   100% |   github.com/golang-jwt/jwt/v4.(*Parser).ParseWithClaims /go/pkg/mod/github.com/golang-jwt/jwt/[email protected]/parser.go:88
----------------------------------------------------------+-------------
         0     0%   100%        1MB  0.46%                | net/http.(*conn).serve /usr/local/go/src/net/http/server.go:1874
                                               1MB   100% |   net/http.newBufioReader /usr/local/go/src/net/http/server.go:845
----------------------------------------------------------+-------------
         0     0%   100%   218.51MB 99.31%                | net/http.(*conn).serve /usr/local/go/src/net/http/server.go:1952
                                          218.51MB   100% |   net/http.serverHandler.ServeHTTP /usr/local/go/src/net/http/server.go:2887
----------------------------------------------------------+-------------
                                               1MB   100% |   net/http.(*conn).serve /usr/local/go/src/net/http/server.go:1874
         0     0%   100%        1MB  0.46%                | net/http.newBufioReader /usr/local/go/src/net/http/server.go:845
                                               1MB   100% |   bufio.NewReader /usr/local/go/src/bufio/bufio.go:63 (inline)
----------------------------------------------------------+-------------
                                          218.51MB   100% |   net/http.(*conn).serve /usr/local/go/src/net/http/server.go:1952
         0     0%   100%   218.51MB 99.31%                | net/http.serverHandler.ServeHTTP /usr/local/go/src/net/http/server.go:2887
                                          218.51MB   100% |   github.com/gin-gonic/gin.(*Engine).ServeHTTP /go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:572
----------------------------------------------------------+-------------
                                            0.50MB   100% |   encoding/json.mapEncoder.encode /usr/local/go/src/encoding/json/encode.go:797
         0     0%   100%     0.50MB  0.23%                | reflect.Value.MapKeys /usr/local/go/src/reflect/value.go:1215
                                            0.50MB   100% |   reflect.mapiterinit /usr/local/go/src/runtime/map.go:1339
----------------------------------------------------------+-------------
                                            0.51MB   100% |   regexp.MustCompile /usr/local/go/src/regexp/regexp.go:309 (inline)
         0     0%   100%     0.51MB  0.23%                | regexp.Compile /usr/local/go/src/regexp/regexp.go:133
                                            0.51MB   100% |   regexp.compile /usr/local/go/src/regexp/regexp.go:178
----------------------------------------------------------+-------------
                                            0.51MB   100% |   github.com/go-playground/validator/v10.init /go/pkg/mod/github.com/go-playground/validator/[email protected]/regexes.go:68
         0     0%   100%     0.51MB  0.23%                | regexp.MustCompile /usr/local/go/src/regexp/regexp.go:309
                                            0.51MB   100% |   regexp.Compile /usr/local/go/src/regexp/regexp.go:133 (inline)
----------------------------------------------------------+-------------
                                            0.51MB   100% |   regexp.Compile /usr/local/go/src/regexp/regexp.go:133
         0     0%   100%     0.51MB  0.23%                | regexp.compile /usr/local/go/src/regexp/regexp.go:178
                                            0.51MB   100% |   regexp/syntax.Compile /usr/local/go/src/regexp/syntax/compile.go:73
----------------------------------------------------------+-------------
                                            0.51MB   100% |   regexp/syntax.(*compiler).compile /usr/local/go/src/regexp/syntax/compile.go:132
         0     0%   100%     0.51MB  0.23%                | regexp/syntax.(*compiler).compile /usr/local/go/src/regexp/syntax/compile.go:109
                                            0.51MB   100% |   regexp/syntax.(*compiler).rune /usr/local/go/src/regexp/syntax/compile.go:257
----------------------------------------------------------+-------------
                                            0.51MB   100% |   regexp/syntax.(*compiler).compile /usr/local/go/src/regexp/syntax/compile.go:146
         0     0%   100%     0.51MB  0.23%                | regexp/syntax.(*compiler).compile /usr/local/go/src/regexp/syntax/compile.go:132
                                            0.51MB   100% |   regexp/syntax.(*compiler).compile /usr/local/go/src/regexp/syntax/compile.go:109
----------------------------------------------------------+-------------
                                            0.51MB   100% |   regexp/syntax.Compile /usr/local/go/src/regexp/syntax/compile.go:73
         0     0%   100%     0.51MB  0.23%                | regexp/syntax.(*compiler).compile /usr/local/go/src/regexp/syntax/compile.go:146
                                            0.51MB   100% |   regexp/syntax.(*compiler).compile /usr/local/go/src/regexp/syntax/compile.go:132
----------------------------------------------------------+-------------
                                            0.51MB   100% |   regexp/syntax.(*compiler).compile /usr/local/go/src/regexp/syntax/compile.go:109
         0     0%   100%     0.51MB  0.23%                | regexp/syntax.(*compiler).rune /usr/local/go/src/regexp/syntax/compile.go:257
                                            0.51MB   100% |   regexp/syntax.(*compiler).inst /usr/local/go/src/regexp/syntax/compile.go:163 (inline)
----------------------------------------------------------+-------------
                                            0.51MB   100% |   regexp.compile /usr/local/go/src/regexp/regexp.go:178
         0     0%   100%     0.51MB  0.23%                | regexp/syntax.Compile /usr/local/go/src/regexp/syntax/compile.go:73
                                            0.51MB   100% |   regexp/syntax.(*compiler).compile /usr/local/go/src/regexp/syntax/compile.go:146
----------------------------------------------------------+-------------
                                            0.51MB   100% |   runtime.main /usr/local/go/src/runtime/proc.go:208
         0     0%   100%     0.51MB  0.23%                | runtime.doInit /usr/local/go/src/runtime/proc.go:6242
                                            0.51MB   100% |   runtime.doInit /usr/local/go/src/runtime/proc.go:6265
----------------------------------------------------------+-------------
                                            0.51MB   100% |   runtime.doInit /usr/local/go/src/runtime/proc.go:6242
         0     0%   100%     0.51MB  0.23%                | runtime.doInit /usr/local/go/src/runtime/proc.go:6265
                                            0.51MB   100% |   github.com/go-playground/validator/v10.init /go/pkg/mod/github.com/go-playground/validator/[email protected]/regexes.go:68
----------------------------------------------------------+-------------
         0     0%   100%     0.51MB  0.23%                | runtime.main /usr/local/go/src/runtime/proc.go:208
                                            0.51MB   100% |   runtime.doInit /usr/local/go/src/runtime/proc.go:6242
----------------------------------------------------------+-------------

My implemented code. See below

_, err := jwt.ParseWithClaims(jwt, claims, func(token *jwt.Token) (interface{}, error) {
		return config.secret, nil
	})
@mfridman
Copy link
Member

mfridman commented Feb 1, 2023

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.

@spksoft
Copy link
Author

spksoft commented Feb 24, 2023

@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.

@mfridman
Copy link
Member

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

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

No branches or pull requests

2 participants