Fix infinite recursion bug for Go SDK (#4516)

gatherDependencySet was not checking for Resources
in the dependency set, which could lead to infinite
recursion.
This commit is contained in:
Levi Blackstone 2020-04-28 18:10:07 -06:00 committed by GitHub
parent 7b17463031
commit d1ba572e1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View file

@ -3,6 +3,9 @@ CHANGELOG
## HEAD (unreleased)
- Fix infinite recursion bug for Go SDK
[#4516](https://github.com/pulumi/pulumi/pull/4516)
- Order secretOutputNames when used in stack references
[#4489](https://github.com/pulumi/pulumi/pull/4489)

View file

@ -454,6 +454,8 @@ func gatherDependencies(v interface{}) []Resource {
return deps
}
var resourceType = reflect.TypeOf((*Resource)(nil)).Elem()
func gatherDependencySet(v reflect.Value, deps map[Resource]struct{}) {
for {
// Check for an Output that we can pull dependencies off of.
@ -464,6 +466,14 @@ func gatherDependencySet(v reflect.Value, deps map[Resource]struct{}) {
}
return
}
// Check for an actual Resource.
if v.Type().Implements(resourceType) {
if v.CanInterface() {
resource := v.Convert(resourceType).Interface().(Resource)
deps[resource] = struct{}{}
}
return
}
switch v.Kind() {
case reflect.Interface, reflect.Ptr: