Skip to content

Commit

Permalink
Prevent race when resolving a property map
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Oct 28, 2022
1 parent ab21df6 commit 0f374b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 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
7 changes: 6 additions & 1 deletion sdk/go/pulumi/types.go
Expand Up @@ -133,6 +133,8 @@ func (o *OutputState) dependencies() []Resource {
if o == nil {
return nil
}
o.cond.L.Lock()
defer o.cond.L.Unlock()
return o.deps
}

Expand Down Expand Up @@ -520,7 +522,10 @@ func (o *OutputState) ApplyTWithContext(ctx context.Context, applier interface{}

// IsSecret returns a bool representing the secretness of the Output
func IsSecret(o Output) bool {
return o.getState().secret
s := o.getState()
s.cond.L.Lock()
defer s.cond.L.Unlock()
return s.secret
}

// Unsecret will unwrap a secret output as a new output with a resolved value and no secretness
Expand Down

0 comments on commit 0f374b1

Please sign in to comment.