Skip to content

Commit 51b3190

Browse files
committed
Fix downstream race conditions with NewAccountFunc
These functions typically modify the ACMEIssuer. Only one such consumer of this API is known (Caddy).
1 parent 693a79b commit 51b3190

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

acmeclient.go

+3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ func (iss *ACMEIssuer) newACMEClientWithAccount(ctx context.Context, useTestCA,
6868
// register account if it is new
6969
if account.Status == "" {
7070
if iss.NewAccountFunc != nil {
71+
// obtain lock here, since NewAccountFunc calls happen concurrently and they typically read and change the issuer
72+
iss.mu.Lock()
7173
account, err = iss.NewAccountFunc(ctx, iss, account)
74+
iss.mu.Unlock()
7275
if err != nil {
7376
return nil, fmt.Errorf("account pre-registration callback: %v", err)
7477
}

acmeissuer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ type ACMEIssuer struct {
132132
// synchronize properly.
133133
email string
134134
agreed bool
135-
mu *sync.Mutex // protects the above grouped fields
135+
mu *sync.Mutex // protects the above grouped fields, as well as entire struct during NewAccountFunc calls
136136
}
137137

138138
// NewACMEIssuer constructs a valid ACMEIssuer based on a template

0 commit comments

Comments
 (0)