Skip to content

Commit 4ba4fb4

Browse files
acme/autocert: fix renewal timer issue
Block when creating the renewal timer, rather than doing it in a goroutine. This fixes an issue where startRenew and stopRenew are called very closely together, and due to lock ordering, stopRenew may be called before startRenew, resulting in the appearance that the renewal timer has been stopped before it has actually been created. This is only an issue in tests, as that is the only place stopRenew is actually used. In particular this issue manifests in TestGetCertiifcate sub-tests, where a httptest server reuses a port across two of the sub-tests. In this case, the renewal calls end up creating dirty state for the subsequent test, which can cause confusing behavior (such as attempting to register an account twice.) Another solution to this problem would be introducing a bool, protected by renewalMu, which indicates if renewal has been halted, and to check it in startRenew to check if stopRenew has already been called, which would allow us to continue calling startRenew in a goroutine and relying on renewalMu locking for ordering. That said I don't see a particularly strong reason to call startRenew concurrently, so this seems like the simplest solution for now. Fixes golang/go#52494 Change-Id: I95420d3fd877572a0b9e408d2f8cd353f6a4e80e Reviewed-on: https://go-review.googlesource.com/c/crypto/+/433016 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
1 parent 35f4265 commit 4ba4fb4

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

acme/autocert/autocert.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ func (m *Manager) cert(ctx context.Context, ck certKey) (*tls.Certificate, error
463463
leaf: cert.Leaf,
464464
}
465465
m.state[ck] = s
466-
go m.startRenew(ck, s.key, s.leaf.NotAfter)
466+
m.startRenew(ck, s.key, s.leaf.NotAfter)
467467
return cert, nil
468468
}
469469

@@ -609,7 +609,7 @@ func (m *Manager) createCert(ctx context.Context, ck certKey) (*tls.Certificate,
609609
}
610610
state.cert = der
611611
state.leaf = leaf
612-
go m.startRenew(ck, state.key, state.leaf.NotAfter)
612+
m.startRenew(ck, state.key, state.leaf.NotAfter)
613613
return state.tlscert()
614614
}
615615

acme/autocert/autocert_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func TestGetCertificate(t *testing.T) {
382382
},
383383
},
384384
{
385-
name: "expiredCache",
385+
name: "almostExpiredCache",
386386
hello: clientHelloInfo("example.org", algECDSA),
387387
domain: "example.org",
388388
prepare: func(t *testing.T, man *Manager, s *acmetest.CAServer) {

0 commit comments

Comments
 (0)