diff --git a/coordinator/main.go b/coordinator/main.go index 6f9bdfee0..e2d01a760 100644 --- a/coordinator/main.go +++ b/coordinator/main.go @@ -10,6 +10,7 @@ import ( "github.com/edgelesssys/nunki/internal/coordapi" "github.com/edgelesssys/nunki/internal/intercom" "github.com/edgelesssys/nunki/internal/logger" + "golang.org/x/sync/errgroup" ) func main() { @@ -26,7 +27,7 @@ func run() (retErr error) { } defer func() { if retErr != nil { - logger.Error(retErr.Error()) + logger.Error("Coordinator terminated after failure", "err", retErr) } }() @@ -46,17 +47,23 @@ func run() (retErr error) { coordS := newCoordAPIServer(meshAuth, caInstance, logger) intercomS := newIntercomServer(meshAuth, caInstance, logger) - go func() { + eg := errgroup.Group{} + + eg.Go(func() error { logger.Info("Coordinator API listening") if err := coordS.Serve(net.JoinHostPort("0.0.0.0", coordapi.Port)); err != nil { - // TODO: collect error using errgroup. - logger.Error("Coordinator API failed to serve", "err", err) + return fmt.Errorf("serving Coordinator API: %w", err) } - }() + return nil + }) - logger.Info("Coordinator intercom listening") - if err := intercomS.Serve(net.JoinHostPort("0.0.0.0", intercom.Port)); err != nil { - return fmt.Errorf("serving intercom: %w", err) - } - return nil + eg.Go(func() error { + logger.Info("Coordinator intercom listening") + if err := intercomS.Serve(net.JoinHostPort("0.0.0.0", intercom.Port)); err != nil { + return fmt.Errorf("serving intercom API: %w", err) + } + return nil + }) + + return eg.Wait() } diff --git a/go.mod b/go.mod index 45f6d8fdd..6b5b633e9 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/stretchr/testify v1.8.4 go.uber.org/goleak v1.3.0 golang.org/x/crypto v0.18.0 + golang.org/x/sync v0.4.0 google.golang.org/grpc v1.60.1 google.golang.org/protobuf v1.32.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index 6ed4cb52a..5c9982edd 100644 --- a/go.sum +++ b/go.sum @@ -80,6 +80,8 @@ golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/packages/default.nix b/packages/default.nix index 12f6aa81d..4650c7798 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -44,7 +44,7 @@ rec { src = goFiles; proxyVendor = true; - vendorHash = "sha256-RySYZYCKOeBp0miqYMQKtc1TQ3NdYgfPj+/vBjhkFpI="; + vendorHash = "sha256-/2GzN6vzMm8NWJYcauR+eJuZAVEV5wi/Wdkbe3KhKOM="; CGO_ENABLED = 0; ldflags = [