Skip to content

Commit d2dbc18

Browse files
authored
Add thread safety documentation for key types (#715)
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
1 parent 846cd4e commit d2dbc18

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

metadata/multirepo/multirepo.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ type MultiRepoConfig struct {
5151
DisableLocalCache bool
5252
}
5353

54-
// MultiRepoClient represents a multi-repository TUF client
54+
// MultiRepoClient represents a multi-repository TUF client.
55+
//
56+
// Thread Safety: MultiRepoClient is NOT safe for concurrent use. If multiple
57+
// goroutines need to use a MultiRepoClient concurrently, external synchronization
58+
// is required (e.g., a sync.Mutex). Alternatively, create separate MultiRepoClient
59+
// instances for each goroutine.
5560
type MultiRepoClient struct {
5661
TUFClients map[string]*updater.Updater
5762
Config *MultiRepoConfig

metadata/trustedmetadata/trustedmetadata.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import (
2424
"github.com/theupdateframework/go-tuf/v2/metadata"
2525
)
2626

27-
// TrustedMetadata struct for storing trusted metadata
27+
// TrustedMetadata struct for storing trusted metadata.
28+
//
29+
// Thread Safety: TrustedMetadata is NOT safe for concurrent use. If multiple
30+
// goroutines need to access a TrustedMetadata instance concurrently, external
31+
// synchronization is required (e.g., a sync.Mutex).
2832
type TrustedMetadata struct {
2933
Root *metadata.Metadata[metadata.RootType]
3034
Snapshot *metadata.Metadata[metadata.SnapshotType]

metadata/updater/updater.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ import (
5858
// target file is already locally cached.
5959
// - DownloadTarget() downloads a target file and ensures it is
6060
// verified correct by the metadata.
61+
//
62+
// Thread Safety: Updater is NOT safe for concurrent use. If multiple goroutines
63+
// need to use an Updater concurrently, external synchronization is required
64+
// (e.g., a sync.Mutex). Alternatively, create separate Updater instances for
65+
// each goroutine.
6166
type Updater struct {
6267
trusted *trustedmetadata.TrustedMetadata
6368
cfg *config.UpdaterConfig

0 commit comments

Comments
 (0)