Skip to content

runtime/race: runaway memory consumption #14533

@dvyukov

Description

@dvyukov

The following benchmark consumes unlimited amount of memory:

func BenchmarkSyncLeak(b *testing.B) {
    const (
        G = 1000
        S = 1000
        H = 10
    )
    var wg sync.WaitGroup
    wg.Add(G)
    for g := 0; g < G; g++ {
        go func() {
            defer wg.Done()
            hold := make([][]uint32, H)
            for i := 0; i < b.N; i++ {
                a := make([]uint32, S)
                atomic.AddUint32(&a[rand.Intn(len(a))], 1)
                hold[rand.Intn(len(hold))] = a
            }
            _ = hold
        }()
    }
    wg.Wait()
}

The main cause is that race runtime does not wipe stale synchronization objects from heap memory blocks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions