@@ -48,32 +48,38 @@ type Manager2 struct {
4848// The manager is using internal synchronization and is safe for concurrent
4949// use. Make sure to call Close when the manager is no longer needed.
5050func NewManager2 (loadCerts func () ([]* Certificate2 , error )) (* Manager2 , error ) {
51+ certUpdateCh := make (chan * Certificate2 , 1 )
52+
5153 // Load initial certificates
5254 certs , err := loadCerts ()
5355 if err != nil {
5456 return nil , err
5557 }
5658
59+ // Subscribe to initial certificates
60+ for _ , cert := range certs {
61+ // no need to store the close function, because
62+ // certificates are closed when they are replaced
63+ // and that will automatically close all subscriptions.
64+ cert .Subscribe (func (updatedCert * Certificate2 ) {
65+ certUpdateCh <- updatedCert
66+ })
67+ }
68+
5769 closeCh := make (chan struct {})
5870
5971 mgr := Manager2 {
6072 close : closeCh ,
6173 }
6274 mgr .certs .Store (& certs )
6375
64- certUpdateCh := make (chan * Certificate2 , 1 )
65-
6676 replaceCerts := func (newCerts []* Certificate2 ) {
6777 oldCerts := mgr .certs .Swap (& newCerts )
6878 for i := range * oldCerts {
6979 (* oldCerts )[i ].Close ()
7080 }
7181
72- // Subscribe to new certificates
7382 for _ , cert := range newCerts {
74- // no need to store the close function, because
75- // certificates are closed when they are replaced
76- // and that will automatically close all subscriptions.
7783 cert .Subscribe (func (updatedCert * Certificate2 ) {
7884 certUpdateCh <- updatedCert
7985 })
@@ -106,7 +112,11 @@ func NewManager2(loadCerts func() ([]*Certificate2, error)) (*Manager2, error) {
106112 subs := append ([]chan * Certificate2 {}, mgr .subscriptions ... )
107113 mgr .subscriptionLock .Unlock ()
108114 for _ , sub := range subs {
109- sub <- cert
115+ select {
116+ case sub <- cert :
117+ default :
118+ log .Printf ("certificate update notification dropped: subscriber channel full" )
119+ }
110120 }
111121 case <- signalCh :
112122 certs , err := loadCerts ()
0 commit comments