https://pulumi.com logo
#golang
Title
# golang
t

tall-needle-56640

12/20/2020, 7:08 AM
In stack.go, what is the concurrency in Run() trying to accomplish? I'm not a Go programmer, but it appears that
pulumi.RunWithContext()
can be run concurrently because it is not called within a lock. Is that desired? Or is all this concurrent code just to protect the state? NOTE: I am trying to port this code to C#
l

lemon-agent-27707

12/20/2020, 6:19 PM
The synchronization code makes sure that languageRuntimeServer.Run calls execute serially. It's possible that the engine could try to initiate more than one of these, and we want to prevent concurrent updates (or unnecessary failures due to conflicts). The flow is that automation api creates an instance of
languageRuntimeServer
and passes its address to the engine via the CLI. The server waits for the engine to call the Run gRPC method. The server has a lock to make sure that the engine doesn't try to start two concurrent updates on the server (could be a retry, guarding against future implementation changes).
t

tall-needle-56640

12/21/2020, 4:11 PM
Right, but it seems like it is possible to have two concurrent updates with the current code:
Thread A enters
Run()
Thread A gets the lock, sets the state from
waiting
to
running
, and releases the lock
Thread A calls
RunWithContext()
Thread B enters
Run()
Thread B gets the lock, sets the state from
running
to
running
, and releases the lock
Thread B calls
RunWithContext()
// Current updates!
Thread A gets the lock, sets the state from
running
to
finished
, and releases the lock
Thread B gets the lock, sets the state from
finished
to
finished
, and releases the lock
l

lemon-agent-27707

12/21/2020, 4:27 PM
Ahh, good catch 🙂
Looks like it should probably share some of the same behavior as the closer: https://github.com/pulumi/pulumi/blob/master/sdk/go/x/auto/stack.go#L819-L829 Mainly, wait to do anything until the state is finished, canceled, or waiting.
3 Views