+
Skip to content

deadlock in Close #57

Closed
Closed
@ykalayy

Description

@ykalayy

Problem

Whenever eviction and close run at the same time. There is a possible deadlock because of the closeLock mutex usage on poo.go:487. We can unlock it whenever we don't need it rather than using defer.

Repreduce UT

func (suit *PoolTestSuite) TestConcurrentCloseAndEvict() {
	ctx := context.Background()
	suit.pool.Config.MinIdle = 1
	suit.pool.Config.SoftMinEvictableIdleTime = time.Millisecond * 100
	suit.pool.Config.TimeBetweenEvictionRuns = time.Millisecond * 500
	suit.factory.destroyLatency = time.Millisecond * 1000 // Destroy takes 1000 ms
	suit.pool.PreparePool(ctx)
	suit.pool.StartEvictor()
	suit.Equal(1, suit.pool.GetNumIdle())
	ticker := time.NewTicker(time.Millisecond * 1000)
	testTimeoutTicker := time.NewTicker(time.Millisecond * 5000) // if time exceeds test fails
	go func() {
		select {
		case <-testTimeoutTicker.C:
			// Time-out
			suit.FailNow("Time is exceeds on pool close")
		}
	}()
	select {
	case <-ticker.C:
		suit.pool.Close(ctx)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载