Skip to content

Commit 1924317

Browse files
committed
Fix chainingBootstrapper to return the first successful address list
Avoids infinite recursion when the chain includes an agentBootstrapper with a server address that points back at this node (via join address loop or external LB) Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
1 parent 9eb79c9 commit 1924317

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

pkg/spegel/bootstrap.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ type chainingBootstrapper struct {
209209
}
210210

211211
// NewChainingBootstrapper returns a p2p bootstrapper that passes through to a list of bootstrappers.
212-
// Addressess are returned from all boostrappers that return successfully.
212+
// Addressess are returned from the first bootstrapper that returns successfully, to prevent infinite
213+
// recursion if this chains through an agentBootstrapper when the server URL is set to an external
214+
// loadbalancer that points back at this node.
213215
func NewChainingBootstrapper(bootstrappers ...routing.Bootstrapper) routing.Bootstrapper {
214216
return &chainingBootstrapper{
215217
bootstrappers: bootstrappers,
@@ -229,20 +231,16 @@ func (c *chainingBootstrapper) Run(ctx context.Context, id string) error {
229231

230232
func (c *chainingBootstrapper) Get(ctx context.Context) ([]peer.AddrInfo, error) {
231233
errs := merr.Errors{}
232-
addrs := []peer.AddrInfo{}
233234
for i := range c.bootstrappers {
234235
b := c.bootstrappers[i]
235236
as, err := b.Get(ctx)
236237
if err != nil {
237238
errs = append(errs, err)
238239
} else {
239-
addrs = append(addrs, as...)
240+
return as, nil
240241
}
241242
}
242-
if len(addrs) == 0 {
243-
return nil, merr.NewErrors(errs...)
244-
}
245-
return addrs, nil
243+
return nil, merr.NewErrors(errs...)
246244
}
247245

248246
func waitForDone(ctx context.Context) error {

0 commit comments

Comments
 (0)