Created
November 24, 2021 23:21
-
-
Save t0yv0/558f3297c3a477ddc5d2c2bd487721b1 to your computer and use it in GitHub Desktop.
Reproduce NPE in Pulumi .NET SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
To reliably hit the race NullPointerException with Pulumi, modify Pulumi.Core Resource.cs constructor to introduce a delay: | |
+ System.Threading.Thread.Sleep(100); | |
+ System.Console.WriteLine($"Delaying resource: {name}"); | |
Deployment.InternalInstance.ReadOrRegisterResource(this, remote, urn => new DependencyResource(urn), args, options); | |
*/ | |
using Pulumi; | |
using Pulumi.Kubernetes.Yaml; | |
using Pulumi.Kubernetes.Core.V1; | |
class MyStack : Stack | |
{ | |
public MyStack() | |
{ | |
var yaml = @" | |
apiVersion: v1 | |
kind: Namespace | |
metadata: | |
name: foo | |
"; | |
// Component Resource with delayed child (defined in yaml). | |
// The child is provisioned in an apply, introducing | |
// concurrency here. | |
var cg = new ConfigGroup("cg", | |
new ConfigGroupArgs | |
{ | |
Yaml = yaml | |
}); | |
// Any resource depending on the Component Resource. This will | |
// race to find the child introduced in `yaml` before the | |
// child's constructor completes. | |
new Namespace("ns", null, new CustomResourceOptions | |
{ | |
DependsOn = cg | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment