Skip to content

cli: remove a workaround when taking profile in debug zip #74133

@tbg

Description

@tbg

Describe the problem

This has nothing to do with CRDB but I need a place to remember this. For some reason, the code below produces a race detector hit.

To Reproduce

var labelSet = pprof.Labels("foo", "bar")

func TestRace(t *testing.T) {
        done := make(chan struct{})
        go func() {
                pprof.Do(context.Background(), labelSet, func(ctx context.Context) {
                        <-done
                })
        }()
        var buf bytes.Buffer
        require.NoError(t, pprof.Lookup("goroutine").WriteTo(&buf, 1))
}

Invoked under make stressrace (possibly it fails every single time though):

WARNING: DATA RACE
Read at 0x00c00019c3b0 by goroutine 24:
  runtime/pprof.(*labelMap).String()
      /usr/local/go/src/runtime/pprof/label.go:46 +0x53
  runtime/pprof.printCountProfile.func1()
      /usr/local/go/src/runtime/pprof/pprof.go:415 +0x178
  runtime/pprof.printCountProfile()
      /usr/local/go/src/runtime/pprof/pprof.go:424 +0x2f1
  runtime/pprof.writeRuntimeProfile()
      /usr/local/go/src/runtime/pprof/pprof.go:732 +0x1b8
  runtime/pprof.writeGoroutine()
      /usr/local/go/src/runtime/pprof/pprof.go:684 +0x8f
  runtime/pprof.(*Profile).WriteTo()
      /usr/local/go/src/runtime/pprof/pprof.go:331 +0x1b0
  github.com/cockroachdb/cockroach/pkg/util/stop.TestRace()
      /Users/tobias/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/tc_test.go:32 +0x124
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /usr/local/go/src/testing/testing.go:1306 +0x47

Previous write at 0x00c00019c3b0 by goroutine 25:
  runtime/pprof.WithLabels()
      /usr/local/go/src/runtime/pprof/label.go:60 +0x88
  runtime/pprof.Do()
      /usr/local/go/src/runtime/pprof/runtime.go:38 +0xf2
  github.com/cockroachdb/cockroach/pkg/util/stop.TestRace.func1()
      /Users/tobias/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/tc_test.go:27 +0x95

Expected behavior

No data race? I don't see a data race.

Additional data / screenshots

This came up in #74070 and in particular requires skipping TestStatusLocalStacks under race.

Jira issue: CRDB-11933

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupTech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior.E-starterMight be suitable for a starter project for new employees or team members.T-kvKV Teamhelp wantedHelp is requested / needed by the one who filed the issue to fix it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions