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

chore(spanner): fix some go vet issues #9758

Merged
merged 10 commits into from May 2, 2024

Conversation

egonelbre
Copy link
Contributor

This fixes some trivial go vet issues. Each commit is dedicated to specific issue class (mostly).

These are not problems per se, however they end up as noise in `go vet`
output.
…able structs

While the copying in these locations doesn't change the result, the
copies end up as noise in go vet output.
@egonelbre egonelbre requested review from a team as code owners April 12, 2024 09:38
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Apr 12, 2024
@noahdietz noahdietz added the automerge: exact Summon MOG for automerging, but approvals need to be against the latest commit label May 1, 2024
Copy link
Contributor

@noahdietz noahdietz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving again since this went a tad stale. Thanks for the tweaks @egonelbre

Copy link
Contributor

Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, one of your required reviews was not approved, or there is a do not merge label. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot.

@gcf-merge-on-green gcf-merge-on-green bot removed the automerge: exact Summon MOG for automerging, but approvals need to be against the latest commit label May 2, 2024
@rahul2393 rahul2393 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@egonelbre
Copy link
Contributor Author

Looks like this failed:

=== NAME  TestMaintainer
    session_test.go:1570: after 15s waiting, got numOpened sessions mismatch
        Got: 23
        Want: 30
--- FAIL: TestMaintainer (15.06s)

But, as far as I can tell this PR doesn't change anything about it.

@noahdietz noahdietz added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@noahdietz
Copy link
Contributor

Running presubmits again, hopefully just a flake

@noahdietz
Copy link
Contributor

Running presubmits again, hopefully just a flake

Looks like it cleared. I'll baby sit the PR to submission - I'm merging other stuff atm

@noahdietz noahdietz added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@noahdietz noahdietz added kokoro:force-run Add this label to force Kokoro to re-run the tests. automerge Merge the pull request once unit tests and other checks pass. labels May 2, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@noahdietz noahdietz added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 2, 2024
@noahdietz
Copy link
Contributor

=== RUN   TestClient_DoForEachRow_ShouldNotEndSpanWithIteratorDoneError
==================
WARNING: DATA RACE
Write at 0x00c000e00048 by goroutine 37939:
  cloud.google.com/go/internal/testutil.(*TestExporter).ExportSpan()
      /go/pkg/mod/cloud.google.com/go@v0.112.2/internal/testutil/trace.go:59 +0x164
  go.opencensus.io/trace.(*span).End.func1()
      /go/pkg/mod/go.opencensus.io@v0.24.0/trace/trace.go:298 +0x24d
  sync.(*Once).doSlow()
      /usr/local/go/src/sync/once.go:74 +0x101
  sync.(*Once).Do()
      /usr/local/go/src/sync/once.go:65 +0x46
  go.opencensus.io/trace.(*span).End()
      /go/pkg/mod/go.opencensus.io@v0.24.0/trace/trace.go:287 +0xa4
  go.opencensus.io/trace.(*Span).End()
      /go/pkg/mod/go.opencensus.io@v0.24.0/trace/trace_api.go:171 +0x15b
  cloud.google.com/go/internal/trace.EndSpan()
      /go/pkg/mod/cloud.google.com/go@v0.112.2/internal/trace/trace.go:125 +0x13c
  cloud.google.com/go/spanner.(*sessionClient).executeBatchCreateSessions.func1()
      /tmpfs/src/google-cloud-go/spanner/sessionclient.go:247 +0x44
  runtime.deferreturn()
      /usr/local/go/src/runtime/panic.go:476 +0x32
  cloud.google.com/go/spanner.(*sessionClient).batchCreateSessions.func2()
      /tmpfs/src/google-cloud-go/spanner/sessionclient.go:234 +0x96

Previous read at 0x00c000e00048 by goroutine 38201:
  cloud.google.com/go/spanner.TestClient_DoForEachRow_ShouldNotEndSpanWithIteratorDoneError()
      /tmpfs/src/google-cloud-go/spanner/client_test.go:4554 +0x30b
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1446 +0x216
  testing.(*T).Run.func1()
      /usr/local/go/src/testing/testing.go:1493 +0x47

Goroutine 37939 (running) created at:
  cloud.google.com/go/spanner.(*sessionClient).batchCreateSessions()
      /tmpfs/src/google-cloud-go/spanner/sessionclient.go:234 +0x51d
  cloud.google.com/go/spanner.(*sessionPool).growPoolLocked()
      /tmpfs/src/google-cloud-go/spanner/session.go:812 +0x1ae
  cloud.google.com/go/spanner.(*sessionPool).initPool()
      /tmpfs/src/google-cloud-go/spanner/session.go:802 +0xaa
  cloud.google.com/go/spanner.newSessionPool()
      /tmpfs/src/google-cloud-go/spanner/session.go:692 +0xb6e
  cloud.google.com/go/spanner.newClientWithConfig()
      /tmpfs/src/google-cloud-go/spanner/client.go:464 +0xc84
  cloud.google.com/go/spanner.NewClientWithConfig()
      /tmpfs/src/google-cloud-go/spanner/client.go:372 +0x137
  cloud.google.com/go/spanner.NewClient()
      /tmpfs/src/google-cloud-go/spanner/client.go:366 +0x6e
  cloud.google.com/go/spanner.makeClient()
      /tmpfs/src/google-cloud-go/spanner/client_test.go:133 +0x2c6
  cloud.google.com/go/spanner.TestClient_EmulatorWithCredentialsFile()
      /tmpfs/src/google-cloud-go/spanner/client_test.go:4285 +0x184
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1446 +0x216
  testing.(*T).Run.func1()
      /usr/local/go/src/testing/testing.go:1493 +0x47

Goroutine 38201 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1493 +0x75d
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1846 +0x99
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1446 +0x216
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1844 +0x7ec
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1726 +0xa84
  cloud.google.com/go/spanner.TestMain()
      /tmpfs/src/google-cloud-go/spanner/integration_test.go:398 +0x10a
  main.main()
      _testmain.go:841 +0x324
==================
    testing.go:1319: race detected during execution of test
--- FAIL: TestClient_DoForEachRow_ShouldNotEndSpanWithIteratorDoneError (0.03s)

Failure on last run was a data race...we should probably look into that separately @rahul2393 @harshachinta

@gcf-merge-on-green gcf-merge-on-green bot merged commit 966f83d into googleapis:main May 2, 2024
8 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label May 2, 2024
@egonelbre egonelbre deleted the govet branch May 2, 2024 18:37
@egonelbre
Copy link
Contributor Author

@noahdietz I usually can reproduce similar issues with targeting specific tests and then running the tests multiple times... e.g. go test -run "TestClient_DoForEachRow_ShouldNotEndSpanWithIteratorDoneError| TestClient_EmulatorWithCredentialsFile" -race -count 10.

As far as I can tell from the trace -- it's happening because the clients are not waiting for every started goroutine to be finished. Nothing is waiting this goroutine to be finished:

go sc.executeBatchCreateSessions(client, createCountForChannel, sc.sessionLabels, sc.md, consumer)

And it seems the tracing is using global vars, which then ends up causing data races.

Without knowing the exact details, I would add a waitgroup / errgoup into sessionClient and when calling close it then must wait for all the started goroutines to be finished.

@egonelbre
Copy link
Contributor Author

@noahdietz I ended up creating #10095 -- I'm not yet sure whether it'll pass the test, but at least it should reduce the likelihood of a race.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants