Skip to content

math/rand: NewSource Method memory overflow #66867

@huyouba1

Description

@huyouba1

Go version

go version go1.19.1 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOENV="/Users/xxx/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/xxx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xxx/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v2/70nz7fqs4bsf1nmqtbk8111h0000gp/T/go-

What did you do?

develop

What did you see happen?

Variable rng memory is not released and continues to grow

Type: inuse_space
Time: Apr 17, 2024 at 10:32am (CST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 2098.23MB, 93.58% of 2242.26MB total
Dropped 130 nodes (cum <= 11.21MB)
Showing top 10 nodes out of 30
      flat  flat%   sum%        cum   cum%
  848.84MB 37.86% 37.86%   848.84MB 37.86%  math/rand.NewSource (inline)
  377.14MB 16.82% 54.68%   388.64MB 17.33%  github.com/IBM/sarama.(*asyncProducer).newPartitionProducer
  345.61MB 15.41% 70.09%  1221.45MB 54.47%  github.com/IBM/sarama.(*asyncProducer).newTopicProducer
  298.12MB 13.30% 83.38%   298.12MB 13.30%  runtime.malg
   56.51MB  2.52% 85.91%    61.51MB  2.74%  github.com/IBM/sarama.(*brokerProducer).run
   49.50MB  2.21% 88.11%    49.50MB  2.21%  github.com/IBM/sarama.(*asyncProducer).newBrokerProducer
      42MB  1.87% 89.99%    74.51MB  3.32%  github.com/IBM/sarama.newAsyncProducer
      27MB  1.20% 91.19%    76.51MB  3.41%  github.com/IBM/sarama.(*asyncProducer).getBrokerProducer
      27MB  1.20% 92.39%   415.64MB 18.54%  github.com/IBM/sarama.(*topicProducer).dispatch
   26.50MB  1.18% 93.58%    26.50MB  1.18%  github.com/IBM/sarama.newTransactionManager
(pprof) list NewSource
Total: 2.19GB
ROUTINE ======================== math/rand.NewSource in /usr/local/go/src/math/rand/rand.go
  848.84MB   848.84MB (flat, cum) 37.86% of Total
         .          .     39:
         .          .     40:// NewSource returns a new pseudo-random Source seeded with the given value.
         .          .     41:// Unlike the default Source used by top-level functions, this source is not
         .          .     42:// safe for concurrent use by multiple goroutines.
         .          .     43:func NewSource(seed int64) Source {
  848.84MB   848.84MB     44:   var rng rngSource
         .          .     45:   rng.Seed(seed)
         .          .     46:   return &rng
         .          .     47:}
         .          .     48:
         .          .     49:// A Rand is a source of random numbers.
(pprof) 

What did you expect to see?

none

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions