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]:A potential goroutine leak #56

Open
xuxiaofan1203 opened this issue Apr 5, 2024 · 0 comments
Open

[Bug]:A potential goroutine leak #56

xuxiaofan1203 opened this issue Apr 5, 2024 · 0 comments

Comments

@xuxiaofan1203
Copy link

xuxiaofan1203 commented Apr 5, 2024

Hello @samuelkarp, When I used fifo, I found a potential bug, I'm not sure, maybe we can discuss to avoid a goleak
blocking position:

fifo/fifo.go

Lines 124 to 133 in 3e17f98

select {
case <-ctx.Done():
select {
case <-f.opened:
default:
f.Close()
}
case <-f.opened:
case <-f.closed:
}

if users use the OpenFilo() with the parameters like this:
f, err := OpenFifo(context.Background(), filepath.Join(tmpdir, "f0"), syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0600)
The select statement will block beacuse there is no cancelFunc to awaken the <-ctx.Done().

I wrote a test function to reproduce the bug considering the test that

func TestFifoCancel(t *testing.T) {

func TestFifoNocancel(t *testing.T) {
	defer goleak.VerifyNone(t)
	tmpdir, err := os.MkdirTemp("", "fifos")
	assert.NoError(t, err)
	defer os.RemoveAll(tmpdir)

	leakCheckWg = &sync.WaitGroup{}
	defer func() {
		leakCheckWg = nil
	}()

	//f, err := OpenFifo(context.Background(), filepath.Join(tmpdir, "f0"), syscall.O_RDONLY|syscall.O_NONBLOCK, 0600)
	f, err := OpenFifo(context.Background(), filepath.Join(tmpdir, "f0"), syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0600)
	assert.Exactly(t, nil, f)
	assert.NotNil(t, err)
	assert.NoError(t, checkWgDone(leakCheckWg))
}

The test result shows it is a goroutine leak, you can use goleak to reproduce the bug.
1712307934228

@xuxiaofan1203 xuxiaofan1203 changed the title A potential goroutine leak [Bug]:A potential goroutine leak Apr 28, 2024
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