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

cache: remove data race in agent cache #6470

Merged
merged 1 commit into from
Sep 12, 2019
Merged

Conversation

rboyer
Copy link
Member

@rboyer rboyer commented Sep 9, 2019

In normal operations there is a read/write race related to request
QueryOptions fields when using the agent cache. An example race:

WARNING: DATA RACE
Read at 0x00c000836950 by goroutine 30:
  github.com/hashicorp/consul/agent/structs.(*ServiceConfigRequest).CacheInfo()
      /go/src/github.com/hashicorp/consul/agent/structs/config_entry.go:506 +0x109
  github.com/hashicorp/consul/agent/cache.(*Cache).getWithIndex()
      /go/src/github.com/hashicorp/consul/agent/cache/cache.go:262 +0x5c
  github.com/hashicorp/consul/agent/cache.(*Cache).notifyBlockingQuery()
      /go/src/github.com/hashicorp/consul/agent/cache/watch.go:89 +0xd7

Previous write at 0x00c000836950 by goroutine 147:
  github.com/hashicorp/consul/agent/cache-types.(*ResolvedServiceConfig).Fetch()
      /go/src/github.com/hashicorp/consul/agent/cache-types/resolved_service_config.go:31 +0x219
  github.com/hashicorp/consul/agent/cache.(*Cache).fetch.func1()
      /go/src/github.com/hashicorp/consul/agent/cache/cache.go:495 +0x112

This patch does a lightweight copy of the request struct so that the
embedded QueryOptions fields that are mutated during Fetch() are scoped
to just that one RPC.

@rboyer rboyer requested a review from a team September 9, 2019 18:44
@rboyer rboyer self-assigned this Sep 9, 2019
@rboyer rboyer force-pushed the fix-agent-cache-data-race branch from 7a40b3d to ab738b6 Compare September 9, 2019 19:48
@rboyer rboyer force-pushed the fix-agent-cache-data-race branch from 495806e to 3b14058 Compare September 11, 2019 14:42
.circleci/config.yml Outdated Show resolved Hide resolved
In normal operations there is a read/write race related to request
QueryOptions fields. An example race:

    WARNING: DATA RACE
    Read at 0x00c000836950 by goroutine 30:
      github.com/hashicorp/consul/agent/structs.(*ServiceConfigRequest).CacheInfo()
          /go/src/github.com/hashicorp/consul/agent/structs/config_entry.go:506 +0x109
      github.com/hashicorp/consul/agent/cache.(*Cache).getWithIndex()
          /go/src/github.com/hashicorp/consul/agent/cache/cache.go:262 +0x5c
      github.com/hashicorp/consul/agent/cache.(*Cache).notifyBlockingQuery()
          /go/src/github.com/hashicorp/consul/agent/cache/watch.go:89 +0xd7

    Previous write at 0x00c000836950 by goroutine 147:
      github.com/hashicorp/consul/agent/cache-types.(*ResolvedServiceConfig).Fetch()
          /go/src/github.com/hashicorp/consul/agent/cache-types/resolved_service_config.go:31 +0x219
      github.com/hashicorp/consul/agent/cache.(*Cache).fetch.func1()
          /go/src/github.com/hashicorp/consul/agent/cache/cache.go:495 +0x112

This patch does a lightweight copy of the request struct so that the
embedded QueryOptions fields that are mutated during Fetch() are scoped
to just that one RPC.
@rboyer rboyer force-pushed the fix-agent-cache-data-race branch from 3b14058 to 2e7b064 Compare September 11, 2019 16:51
Copy link
Member

@hanshasselberg hanshasselberg left a comment

Choose a reason for hiding this comment

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

👍

@rboyer rboyer merged commit 20eb0d3 into master Sep 12, 2019
@rboyer rboyer deleted the fix-agent-cache-data-race branch September 12, 2019 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants