Merge pull request #650 from go-kratos/bugfix/container-pool-deadlock

fix pool deadlock
pull/652/head
Windfarer 4 years ago committed by GitHub
commit 25db576747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .github/workflows/go.yml
  2. 1
      go.mod
  3. 2
      go.sum
  4. 1
      pkg/container/pool/list.go
  5. 5
      pkg/container/pool/slice.go

@ -92,8 +92,8 @@ jobs:
- name: Set up Env
run: |
echo "::set-env name=GOPATH::$(go env GOPATH)"
echo "::add-path::$(go env GOPATH)/bin"
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Check out code into the Go module directory
uses: actions/checkout@v2

@ -32,6 +32,7 @@ require (
github.com/leodido/go-urn v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/montanaflynn/stats v0.5.0
github.com/openzipkin/zipkin-go v0.2.1
github.com/otokaze/mock v0.0.0-20190125081256-8282b7a7c7c3

@ -465,8 +465,6 @@ google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRn
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.28.0 h1:bO/TA4OxCOummhSf10siHuG7vJOiwh7SpRpFZDkOgl4=
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
google.golang.org/grpc v1.28.1 h1:C1QC6KzgSiLyBabDi87BbjaGreoRgGUF5nOyvfrAZ1k=
google.golang.org/grpc v1.28.1/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=

@ -50,7 +50,6 @@ func NewList(c *Config) *List {
// Reload reload config.
func (p *List) Reload(c *Config) error {
p.mu.Lock()
p.startCleanerLocked(time.Duration(c.IdleTimeout))
p.conf = c
p.mu.Unlock()
return nil

@ -61,7 +61,6 @@ func NewSlice(c *Config) *Slice {
// Reload reload config.
func (p *Slice) Reload(c *Config) error {
p.mu.Lock()
p.startCleanerLocked(time.Duration(c.IdleTimeout))
p.setActive(c.Active)
p.setIdle(c.Idle)
p.conf = c
@ -260,7 +259,6 @@ func (p *Slice) openNewItem(ctx context.Context) {
//
// If n <= 0, no idle items are retained.
func (p *Slice) setIdle(n int) {
p.mu.Lock()
if n > 0 {
p.conf.Idle = n
} else {
@ -278,7 +276,6 @@ func (p *Slice) setIdle(n int) {
closing = p.freeItem[maxIdle:]
p.freeItem = p.freeItem[:maxIdle]
}
p.mu.Unlock()
for _, c := range closing {
c.close()
}
@ -293,13 +290,11 @@ func (p *Slice) setIdle(n int) {
// If n <= 0, then there is no limit on the number of open items.
// The default is 0 (unlimited).
func (p *Slice) setActive(n int) {
p.mu.Lock()
p.conf.Active = n
if n < 0 {
p.conf.Active = 0
}
syncIdle := p.conf.Active > 0 && p.maxIdleItemsLocked() > p.conf.Active
p.mu.Unlock()
if syncIdle {
p.setIdle(n)
}

Loading…
Cancel
Save