Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit 8a115c2

Browse files
committed
notarize: limit concurrent uploads to avoid error -18000
1 parent 56f3b74 commit 8a115c2

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

cmd/gon/item.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,27 @@ type processOptions struct {
4343
// Prefix is the prefix string for output
4444
Prefix string
4545

46-
// Lock protects access to the terminal output.
47-
Lock *sync.Mutex
46+
// OutputLock protects access to the terminal output.
47+
//
48+
// UploadLock protects simultaneous notary submission.
49+
OutputLock *sync.Mutex
50+
UploadLock *sync.Mutex
4851
}
4952

5053
// notarize notarize & staples the item.
5154
func (i *item) notarize(ctx context.Context, opts *processOptions) error {
52-
lock := opts.Lock
55+
lock := opts.OutputLock
5356

5457
// Start notarization
5558
_, err := notarize.Notarize(ctx, &notarize.Options{
56-
File: i.Path,
57-
BundleId: opts.Config.BundleId,
58-
Username: opts.Config.AppleId.Username,
59-
Password: opts.Config.AppleId.Password,
60-
Provider: opts.Config.AppleId.Provider,
61-
Logger: opts.Logger.Named("notarize"),
62-
Status: &statusHuman{Prefix: opts.Prefix, Lock: lock},
59+
File: i.Path,
60+
BundleId: opts.Config.BundleId,
61+
Username: opts.Config.AppleId.Username,
62+
Password: opts.Config.AppleId.Password,
63+
Provider: opts.Config.AppleId.Provider,
64+
Logger: opts.Logger.Named("notarize"),
65+
Status: &statusHuman{Prefix: opts.Prefix, Lock: lock},
66+
UploadLock: opts.UploadLock,
6367
})
6468

6569
// Save our state

cmd/gon/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,19 @@ func realMain() int {
176176

177177
// Start our notarizations
178178
var wg sync.WaitGroup
179-
var lock sync.Mutex
179+
var lock, uploadLock sync.Mutex
180180
var totalErr error
181181
for idx := range items {
182182
wg.Add(1)
183183
go func(idx int) {
184184
defer wg.Done()
185185

186186
err := items[idx].notarize(context.Background(), &processOptions{
187-
Config: cfg,
188-
Lock: &lock,
189-
Logger: logger,
190-
Prefix: prefixes[idx],
187+
Config: cfg,
188+
Logger: logger,
189+
Prefix: prefixes[idx],
190+
OutputLock: &lock,
191+
UploadLock: &uploadLock,
191192
})
192193

193194
if err != nil {

notarize/notarize.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os/exec"
88
"strings"
9+
"sync"
910
"time"
1011

1112
"github.com/hashicorp/go-hclog"
@@ -32,6 +33,12 @@ type Options struct {
3233
// providers.
3334
Provider string
3435

36+
// UploadLock, if specified, will limit concurrency when uploading
37+
// packages. The notary submission process does not allow concurrent
38+
// uploads of packages with the same bundle ID, it appears. If you set
39+
// this lock, we'll hold the lock while we upload.
40+
UploadLock *sync.Mutex
41+
3542
// Status, if non-nil, will be invoked with status updates throughout
3643
// the notarization process.
3744
Status Status
@@ -66,9 +73,16 @@ func Notarize(ctx context.Context, opts *Options) (*Info, error) {
6673
status = noopStatus{}
6774
}
6875

76+
lock := opts.UploadLock
77+
if lock == nil {
78+
lock = &sync.Mutex{}
79+
}
80+
6981
// First perform the upload
82+
lock.Lock()
7083
status.Submitting()
7184
uuid, err := upload(ctx, opts)
85+
lock.Unlock()
7286
if err != nil {
7387
return nil, err
7488
}

0 commit comments

Comments
 (0)