1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-07 23:02:12 +02:00

fix pool deadlock

This commit is contained in:
chenzhihui 2020-12-01 12:47:35 +08:00
parent e502a9f491
commit 0e5463652f
2 changed files with 2 additions and 6 deletions

View File

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

View File

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