Skip to content

Commit

Permalink
coordinator: use errgroup in main
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Meyer <[email protected]>
  • Loading branch information
katexochen committed Jan 18, 2024
1 parent 3824934 commit 2316b21
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
27 changes: 17 additions & 10 deletions coordinator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
}
}()

Expand All @@ -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()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ rec {

src = goFiles;
proxyVendor = true;
vendorHash = "sha256-RySYZYCKOeBp0miqYMQKtc1TQ3NdYgfPj+/vBjhkFpI=";
vendorHash = "sha256-/2GzN6vzMm8NWJYcauR+eJuZAVEV5wi/Wdkbe3KhKOM=";

CGO_ENABLED = 0;
ldflags = [
Expand Down

0 comments on commit 2316b21

Please sign in to comment.