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

Deadlock occurs when the pool parent context is canceled with queued tasks in the worker. #61

Closed
CorentinClabaut opened this issue Jun 7, 2024 · 0 comments · Fixed by #62

Comments

@CorentinClabaut
Copy link
Collaborator

The following test will block forever:

func TestSubmitWithContextCancelWithIdleTasks(t *testing.T) {

	ctx, cancel := context.WithCancel(context.Background())

	pool := pond.New(1, 5, pond.Context(ctx))

	var doneCount, taskCount int32

	// Submit a long-running, cancellable task
	pool.Submit(func() {
		atomic.AddInt32(&taskCount, 1)
		select {
		case <-ctx.Done():
			return
		case <-time.After(1 * time.Minute):
			atomic.AddInt32(&doneCount, 1)
			return
		}
	})

	// Submit a long-running, cancellable task
	pool.Submit(func() {
		atomic.AddInt32(&taskCount, 1)
		select {
		case <-ctx.Done():
			return
		case <-time.After(1 * time.Minute):
			atomic.AddInt32(&doneCount, 1)
			return
		}
	})

	// Cancel the context
	cancel()

	pool.StopAndWait()

	assertEqual(t, int32(1), atomic.LoadInt32(&taskCount))
	assertEqual(t, int32(0), atomic.LoadInt32(&doneCount))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant