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

Bug: Potential deadlock in case of events starvation #684

Open
vadimalekseev opened this issue Oct 17, 2024 · 0 comments · May be fixed by #685
Open

Bug: Potential deadlock in case of events starvation #684

vadimalekseev opened this issue Oct 17, 2024 · 0 comments · May be fixed by #685
Labels
enhancement New feature or request

Comments

@vadimalekseev
Copy link
Collaborator

vadimalekseev commented Oct 17, 2024

Subject code here – in usual case, we wait for the signal of new event. But it may happen that all events are back in the pool before the Wait call.

This test can reproduce this beheivior:

func TestDeadLock(t *testing.T) {
	const (
		poolCapacity = 32
		concurrency  = 64
	)
	pool := newEventPool(poolCapacity, DefaultAvgInputEventSize)
	for i := 0; i < 100_000; i++ {
		fmt.Println("new test iteration", i)
		wg := new(sync.WaitGroup)
		wg.Add(concurrency)
		for i := 0; i < concurrency; i++ {
			go func() {
				defer wg.Done()
				e := pool.get()
				runtime.Gosched()
				pool.back(e)
			}()
		}
		wg.Wait()
	}
}

Solution:
We have to run a goroutine that will force the Broadcast/Signal every timer tick. I'll send PR by the end of the week.

@vadimalekseev vadimalekseev added the enhancement New feature or request label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant