Skip to content

Commit

Permalink
Lock in the plugin mapper (#14721)
Browse files Browse the repository at this point in the history
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

Quick fix for #14718.

This could probably be smarter but this will unblock the use of the new
converter for providers.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works - I don't think a method level lock _needs_ a test, but
I've left a comment that if we try to make this smarter it will need
parallel tests written for it.
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change - users won't have
observed this behavior, just pulumi internal usage.
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
  • Loading branch information
Frassle committed Dec 8, 2023
1 parent 7cf51b2 commit d0c3cfb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/codegen/convert/plugin_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"github.com/blang/semver"

Expand Down Expand Up @@ -106,6 +107,7 @@ type pluginMapper struct {
plugins []mapperPluginSpec
entries map[string][]byte
installProvider func(tokens.Package) *semver.Version
lock sync.Mutex
}

func NewPluginMapper(ws Workspace,
Expand Down Expand Up @@ -287,6 +289,13 @@ func (l *pluginMapper) getMappingsForPlugin(pluginSpec *mapperPluginSpec, provid
}

func (l *pluginMapper) GetMapping(ctx context.Context, provider string, pulumiProvider string) ([]byte, error) {
// See https://github.com/pulumi/pulumi/issues/14718 for why we need this lock. It may be possible to be
// smarter about this and only lock when mutating, or at least splitting to a read/write lock, but this is
// a quick fix to unblock providers. If you do attempt this then write tests to ensure this doesn't
// regress #14718.
l.lock.Lock()
defer l.lock.Unlock()

// If we already have an entry for this provider, use it
if entry, has := l.entries[provider]; has {
return entry, nil
Expand Down

0 comments on commit d0c3cfb

Please sign in to comment.