Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable concurrent process to construct persistent caches #23619

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/azidentity/cache/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
* `New` no longer returns an error when called simultaneously in two processes

### Other Changes

Expand Down
9 changes: 6 additions & 3 deletions sdk/azidentity/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"bytes"
"context"
"fmt"
"math/rand"
"path/filepath"
"sync"
"time"
Expand All @@ -29,14 +30,16 @@ var (
// tryStorage tests the storage implementation by round-tripping data
tryStorage = func() {
const errFmt = "persistent storage isn't available due to error %q"
s, err := storage("azidentity-test-cache")
// random content prevents conflict with concurrent processes executing this function
n := fmt.Sprint(rand.Int())
s, err := storage("azidentity-test" + n)
if err != nil {
storageError = fmt.Errorf(errFmt, err)
return
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
in := []byte("test")
in := []byte(n)
err = s.Write(ctx, in)
if err != nil {
storageError = fmt.Errorf(errFmt, err)
Expand All @@ -48,7 +51,7 @@ var (
return
}
if !bytes.Equal(in, out) {
storageError = fmt.Errorf(errFmt, "read doesn't match write")
storageError = fmt.Errorf(errFmt, "reading or writing cache data failed")
}
err = s.Delete(ctx)
if err != nil {
Expand Down