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

Method Serve

internal/proxy/proxy.go:671–708  ·  view source on GitHub ↗

Serve starts proxying connections for all configured instances using the associated socket.

(ctx context.Context, notify func())

Source from the content-addressed store, hash-verified

669// Serve starts proxying connections for all configured instances using the
670// associated socket.
671func (c *Client) Serve(ctx context.Context, notify func()) error {
672 ctx, cancel := context.WithCancel(ctx)
673 defer cancel()
674
675 if c.fuseDir != "" {
676 return c.serveFuse(ctx, notify)
677 }
678
679 if c.conf.RunConnectionTest {
680 c.logger.Infof("Connection test started")
681 if _, err := c.CheckConnections(ctx); err != nil {
682 c.logger.Errorf("Connection test failed")
683 return err
684 }
685 c.logger.Infof("Connection test passed")
686 }
687
688 exitCh := make(chan error)
689 for _, m := range c.mnts {
690 go func(mnt *socketMount) {
691 err := c.serveSocketMount(ctx, mnt)
692 if err != nil {
693 select {
694 // Best effort attempt to send error.
695 // If this send fails, it means the reading goroutine has
696 // already pulled a value out of the channel and is no longer
697 // reading any more values. In other words, we report only the
698 // first error.
699 case exitCh <- err:
700 default:
701 return
702 }
703 }
704 }(m)
705 }
706 notify()
707 return <-exitCh
708}
709
710// MultiErr is a group of errors wrapped into one.
711type MultiErr []error

Callers 11

newTestClientFunction · 0.95
TestClientClosesCleanlyFunction · 0.95
TestClosesWithErrorFunction · 0.95
TestClientConnCountFunction · 0.95
TestCheckConnectionsFunction · 0.95
TestRunConnectionCheckFunction · 0.95
runSignalWrapperFunction · 0.95

Calls 5

serveFuseMethod · 0.95
CheckConnectionsMethod · 0.95
serveSocketMountMethod · 0.95
InfofMethod · 0.65
ErrorfMethod · 0.65

Tested by 10

newTestClientFunction · 0.76
TestClientClosesCleanlyFunction · 0.76
TestClosesWithErrorFunction · 0.76
TestClientConnCountFunction · 0.76
TestCheckConnectionsFunction · 0.76
TestRunConnectionCheckFunction · 0.76