Skip to content

A potential goroutine leak in daemon/logger/ring_test.go #49717

@user12031

Description

@user12031

Description

When the newRingLogger is created.

func TestRingLogger(t *testing.T) {
mockLog := &mockLogger{make(chan *Message)} // no buffer on this channel
ring := newRingLogger(mockLog, Info{}, 1)
defer ring.setClosed()

The defer ring.Close() method should be called to awaken the cond.Wait().

moby/daemon/logger/ring.go

Lines 192 to 194 in 37f8662

for len(r.queue) == 0 && !r.closed {
r.wait.Wait()
}

However, the actual method invoked is defer ring.setClosed(), which doesn't invoke r.wait.Broadcast(), resulting in goroutine leak.

Reproduce

You could use goleak to reproduce the bug in the function as follows.

func TestRingLogger(t *testing.T) {

func TestRingLogger(t *testing.T) {
	defer goleak.VerifyNone(t)
        xxx
}

The result is similar to this:

Image

Expected behavior

How to fix the bug:
invoking defer ring.Close() instead of defer ring.setClosed() in the function.

docker version

latest

docker info

-

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/loggingexp/beginnerhelp wantedkind/bugBugs are bugs. The cause may or may not be known at triage time so debugging may be needed.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions