TUN-3706: Quit if any origin service fails to start

This commit is contained in:
Adam Chalmers 2020-12-30 13:48:19 -06:00
parent 32336859f8
commit b855e33327
3 changed files with 13 additions and 5 deletions

View File

@ -339,7 +339,9 @@ func StartServer(
errC <- metrics.ServeMetrics(metricsListener, shutdownC, readinessCh, log) errC <- metrics.ServeMetrics(metricsListener, shutdownC, readinessCh, log)
}() }()
ingressRules.StartOrigins(&wg, log, shutdownC, errC) if err := ingressRules.StartOrigins(&wg, log, shutdownC, errC); err != nil {
return err
}
reconnectCh := make(chan origin.ReconnectSignal, 1) reconnectCh := make(chan origin.ReconnectSignal, 1)
if c.IsSet("stdin-control") { if c.IsSet("stdin-control") {

View File

@ -113,12 +113,18 @@ func (ing Ingress) IsEmpty() bool {
} }
// StartOrigins will start any origin services managed by cloudflared, e.g. proxy servers or Hello World. // StartOrigins will start any origin services managed by cloudflared, e.g. proxy servers or Hello World.
func (ing Ingress) StartOrigins(wg *sync.WaitGroup, log *zerolog.Logger, shutdownC <-chan struct{}, errC chan error) { func (ing Ingress) StartOrigins(
wg *sync.WaitGroup,
log *zerolog.Logger,
shutdownC <-chan struct{},
errC chan error,
) error {
for _, rule := range ing.Rules { for _, rule := range ing.Rules {
if err := rule.Service.start(wg, log, shutdownC, errC, rule.Config); err != nil { if err := rule.Service.start(wg, log, shutdownC, errC, rule.Config); err != nil {
log.Error().Msgf("Error starting local service %s: %s", rule.Service, err) return errors.Wrapf(err, "Error starting local service %s", rule.Service)
} }
} }
return nil
} }
// CatchAll returns the catch-all rule (i.e. the last rule) // CatchAll returns the catch-all rule (i.e. the last rule)

View File

@ -123,7 +123,7 @@ func TestProxySingleOrigin(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
errC := make(chan error) errC := make(chan error)
ingressRule.StartOrigins(&wg, &log, ctx.Done(), errC) require.NoError(t, ingressRule.StartOrigins(&wg, &log, ctx.Done(), errC))
client := NewClient(ingressRule, testTags, &log) client := NewClient(ingressRule, testTags, &log)
t.Run("testProxyHTTP", testProxyHTTP(t, client)) t.Run("testProxyHTTP", testProxyHTTP(t, client))
@ -256,7 +256,7 @@ func TestProxyMultipleOrigins(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
errC := make(chan error) errC := make(chan error)
var wg sync.WaitGroup var wg sync.WaitGroup
ingress.StartOrigins(&wg, &log, ctx.Done(), errC) require.NoError(t, ingress.StartOrigins(&wg, &log, ctx.Done(), errC))
client := NewClient(ingress, testTags, &log) client := NewClient(ingress, testTags, &log)