@@ -600,13 +600,22 @@ func (cfg *Config) handshakeMaintenance(ctx context.Context, hello *tls.ClientHe
600
600
cfg .certCache .mu .Unlock ()
601
601
}
602
602
603
- // Check ARI status
604
- if ! cfg .DisableARI && cert .ari .NeedsRefresh () {
603
+ // Check ARI status, but it's only relevant if the certificate is not expired (otherwise, we already know it needs renewal!)
604
+ if ! cfg .DisableARI && cert .ari .NeedsRefresh () && time . Now (). Before ( cert . Leaf . NotAfter ) {
605
605
// update ARI in a goroutine to avoid blocking an active handshake, since the results of
606
606
// this do not strictly affect the handshake; even though the cert may be updated with
607
607
// the new ARI, it is also updated in the cache and in storage, so future handshakes
608
608
// will utilize it
609
- go func (ctx context.Context , hello * tls.ClientHelloInfo , cert Certificate , logger * zap.Logger ) {
609
+ go func (hello * tls.ClientHelloInfo , cert Certificate , logger * zap.Logger ) {
610
+ // TODO: a different context that isn't tied to the handshake is probably better
611
+ // than a generic background context; maybe a longer-lived server config context,
612
+ // or something that the importing package sets on the Config struct; for example,
613
+ // a Caddy config context could be good, so that ARI updates will continue after
614
+ // the handshake goes away, but will be stopped if the underlying server is stopped
615
+ // (for now, use an unusual timeout to help recognize it in log patterns, if needed)
616
+ ctx , cancel := context .WithTimeout (context .Background (), 8 * time .Minute )
617
+ defer cancel ()
618
+
610
619
var err error
611
620
// we ignore the second return value here because we check renewal status below regardless
612
621
cert , _ , err = cfg .updateARI (ctx , cert , logger )
@@ -617,7 +626,7 @@ func (cfg *Config) handshakeMaintenance(ctx context.Context, hello *tls.ClientHe
617
626
if err != nil {
618
627
logger .Error ("renewing certificate based on updated ARI" , zap .Error (err ))
619
628
}
620
- }(ctx , hello , cert , logger )
629
+ }(hello , cert , logger )
621
630
}
622
631
623
632
// We attempt to replace any certificates that were revoked.
0 commit comments