Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

internal/ceb: do not block child process startup on URL service conn #544

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions internal/ceb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ func (ceb *CEB) initConfigStream(ctx context.Context, cfg *config, isRetry bool)
ceb.childCmd.Env = append(ceb.childCmd.Env, cv.Name+"="+cv.Value)
}

// If we have URL service configuration, start it.
// If we have URL service configuration, start it. We start this in a goroutine
// since we don't need to block starting up our application on this.
if url := resp.Config.UrlService; url != nil {
if err := ceb.initURLService(ctx, cfg.URLServicePort, url); err != nil {
return err
}
go func() {
if err := ceb.initURLService(ctx, cfg.URLServicePort, url); err != nil {
log.Warn("error starting URL service", "err", err)
}
}()
} else {
log.Debug("no URL service configuration, will not register with URL service")
}
Expand Down
17 changes: 10 additions & 7 deletions internal/ceb/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,37 @@ func (ceb *CEB) initURLService(ctx context.Context, port int, cfg *pb.Entrypoint

g, err := agent.NewAgent(L.Named("agent"))
if err != nil {
// NewAgent should never fail, this just sets some fields and returns
// a struct. Therefore, we won't ever retry on this.
return errors.Wrapf(err, "error configuring agent")
}
g.RootCAs, _ = gocertifi.CACerts()

g.Token = cfg.Token
target := fmt.Sprintf(":%d", port)

labels := hznpb.ParseLabelSet(cfg.Labels)
// Setup the Mozilla CA cert bundle. We can ignore the error because
// this never fails, it only returns an error for backwards compat reasons.
g.RootCAs, _ = gocertifi.CACerts()

// Add our service to route to.
labels := hznpb.ParseLabelSet(cfg.Labels)
target := fmt.Sprintf(":%d", port)
_, err = g.AddService(&agent.Service{
Type: "http",
Labels: labels,
Handler: agent.HTTPHandler("http://" + target),
})

if err != nil {
// This can also never fail.
return errors.Wrapf(err, "error registering service")
}

L.Debug("discovering hubs")

dc, err := discovery.NewClient(cfg.ControlAddr)
if err != nil {
// This shouldn't fail so we don't have to retry at the time of writing.
return errors.Wrapf(err, "error conecting to waypoint control service")
}

L.Debug("refreshing data")

err = dc.Refresh(ctx)
if err != nil {
return errors.Wrapf(err, "error discovering network endpoints")
Expand Down