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

worker.go中executeTaskWithTimeout死锁问题 #21

Open
zzjha-cn opened this issue Nov 29, 2023 · 0 comments
Open

worker.go中executeTaskWithTimeout死锁问题 #21

zzjha-cn opened this issue Nov 29, 2023 · 0 comments

Comments

@zzjha-cn
Copy link

worker.go中,executeTaskWithTimeout执行有超时限制的任务会死锁。

image

执行代码:

func main() {
	var errCount int32

	pool := gopool.NewGoPool(100, gopool.WithTimeout(1*time.Second), gopool.WithErrorCallback(func(err error) {
		fmt.Println("get a error")
		atomic.StoreInt32(&errCount, 1)
	}))
	defer pool.Release()

	// 超时任务
	// pool.AddTask(func() (interface{}, error) {
	// 	time.Sleep(2 * time.Second)
	// 	return nil, nil
	// })

	// 不超时任务
	pool.AddTask(func() (interface{}, error) {
		fmt.Println("run normal task")
		return nil, nil
	})
	pool.AddTask(func() (interface{}, error) {
		fmt.Println("run normal task")
		return nil, nil
	})
	pool.AddTask(func() (interface{}, error) {
		fmt.Println("run normal task")
		return nil, nil
	})

	pool.Wait()

	fmt.Println("err count:", errCount)
}

因为result的chan接收到值后,会在下面等待err的chan 消息,但是此时已经没有发送方了。

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

1 participant