| 516 | } |
| 517 | |
| 518 | func (c *Client) checkVersion() (err error) { |
| 519 | var wg sync.WaitGroup |
| 520 | |
| 521 | eps := c.Endpoints() |
| 522 | errc := make(chan error, len(eps)) |
| 523 | ctx, cancel := context.WithCancel(c.ctx) |
| 524 | if c.cfg.DialTimeout > 0 { |
| 525 | cancel() |
| 526 | ctx, cancel = context.WithTimeout(c.ctx, c.cfg.DialTimeout) |
| 527 | } |
| 528 | |
| 529 | wg.Add(len(eps)) |
| 530 | for _, ep := range eps { |
| 531 | // if cluster is current, any endpoint gives a recent version |
| 532 | go func(e string) { |
| 533 | defer wg.Done() |
| 534 | resp, rerr := c.Status(ctx, e) |
| 535 | if rerr != nil { |
| 536 | errc <- rerr |
| 537 | return |
| 538 | } |
| 539 | vs, serr := semver.NewVersion(resp.Version) |
| 540 | if serr != nil { |
| 541 | errc <- serr |
| 542 | return |
| 543 | } |
| 544 | |
| 545 | if vs.LessThan(*minSupportedVersion()) { |
| 546 | rerr = ErrOldCluster |
| 547 | } |
| 548 | errc <- rerr |
| 549 | }(ep) |
| 550 | } |
| 551 | // wait for success |
| 552 | for range eps { |
| 553 | if err = <-errc; err != nil { |
| 554 | break |
| 555 | } |
| 556 | } |
| 557 | cancel() |
| 558 | wg.Wait() |
| 559 | return err |
| 560 | } |
| 561 | |
| 562 | // ActiveConnection returns the current in-use connection |
| 563 | func (c *Client) ActiveConnection() *grpc.ClientConn { return c.conn } |