Skip to content

Commit

Permalink
Merge #11186
Browse files Browse the repository at this point in the history
11186: Prevent race when resolving a property map r=iwahbe a=iwahbe

I encountered a problem trying to flush non-determinism out of pulumi-yaml. Running our tests with high `--count=N` values resulted in panics from concurrent accesses to `Ouptput` values. These changes allow running `go test -count=500 -race  ./...` without errors (caused by pulumi/pulumi).

Co-authored-by: Ian Wahbe <ian@wahbe.com>
  • Loading branch information
bors[bot] and iwahbe committed Oct 28, 2022
2 parents bbde400 + 211bd3e commit 8659cc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: sdk/go,yaml
description: Prevent race on resource output
6 changes: 4 additions & 2 deletions sdk/go/pulumi/context.go
Expand Up @@ -1178,8 +1178,6 @@ func (state *resourceState) resolve(ctx *Context, err error, inputs *resourceInp
return
}

state.rawOutputs.getState().resolve(outprops, true, false, nil)

outprops["urn"] = resource.NewStringProperty(urn)
if id != "" || !dryrun {
outprops["id"] = resource.NewStringProperty(id)
Expand All @@ -1204,6 +1202,10 @@ func (state *resourceState) resolve(ctx *Context, err error, inputs *resourceInp
}
}

// We need to wait until after we finish mutating outprops to resolve. Resolving
// unlocks multithreaded access to the resolved value, making mutation a data race.
state.rawOutputs.getState().resolve(outprops, true, false, nil)

for k, output := range state.outputs {
// If this is an unknown or missing value during a dry run, do nothing.
v, ok := outprops[resource.PropertyKey(k)]
Expand Down

0 comments on commit 8659cc8

Please sign in to comment.