MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / CheckConnections

Method CheckConnections

internal/proxy/proxy.go:618–661  ·  view source on GitHub ↗

CheckConnections dials each registered instance and reports the number of connections checked and any errors that may have occurred.

(ctx context.Context)

Source from the content-addressed store, hash-verified

616// CheckConnections dials each registered instance and reports the number of
617// connections checked and any errors that may have occurred.
618func (c *Client) CheckConnections(ctx context.Context) (int, error) {
619 var (
620 wg sync.WaitGroup
621 errCh = make(chan error, len(c.mnts))
622 mnts = c.mnts
623 )
624 if c.fuseDir != "" {
625 mnts = c.fuseMounts()
626 }
627 for _, mnt := range mnts {
628 wg.Add(1)
629 go func(m *socketMount) {
630 defer wg.Done()
631 conn, err := c.dialer.Dial(ctx, m.inst, m.dialOpts...)
632 if err != nil {
633 errCh <- err
634 return
635 }
636 cErr := conn.Close()
637 if cErr != nil {
638 c.logger.Errorf(
639 "connection check failed to close connection for %v: %v",
640 m.inst, cErr,
641 )
642 }
643 }(mnt)
644 }
645 wg.Wait()
646
647 var mErr MultiErr
648 for i := 0; i < len(mnts); i++ {
649 select {
650 case err := <-errCh:
651 mErr = append(mErr, err)
652 default:
653 continue
654 }
655 }
656 mLen := len(mnts)
657 if len(mErr) > 0 {
658 return mLen, mErr
659 }
660 return mLen, nil
661}
662
663// ConnCount returns the number of open connections and the maximum allowed
664// connections. Returns 0 when the maximum allowed connections have not been set.

Callers 3

ServeMethod · 0.95
TestCheckConnectionsFunction · 0.95
TestFUSECheckConnectionsFunction · 0.80

Calls 6

fuseMountsMethod · 0.95
DoneMethod · 0.80
WaitMethod · 0.80
DialMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.45

Tested by 2

TestCheckConnectionsFunction · 0.76
TestFUSECheckConnectionsFunction · 0.64