[Bug]:A potential goroutine leak

Open
#56 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
go

Research direction

Start at fifo.go lines 124-133 and compare the behavior with fifo_test.go around line 47. Run the supplied TestFifoNocancel reproduction with goleak and inspect how OpenFifo behaves with context.Background(), O_RDONLY|O_CREAT|O_NONBLOCK. Done means the reproduction no longer reports a goroutine leak while the existing FIFO tests still pass.

Written by the indexing model from the issue text.

Description

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:
https://github.com/containerd/fifo/blob/3e17f98903a83f1a6c7368ea4694e6861161d6bd/fifo.go#L124-L133
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 https://github.com/containerd/fifo/blob/3e17f98903a83f1a6c7368ea4694e6861161d6bd/fifo_test.go#L47

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

Dominant language
Go
Stars
87
Forks
33
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from containerd/fifo

All issues in containerd/fifo

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.