Skip to content

Commit

Permalink
prepare 6.6.4 release (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaunchDarklyReleaseBot authored Feb 7, 2022
1 parent 8b4654c commit ed578bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Property in file | Environment var | Type | Default | Descriptio
`streamUri` | `STREAM_URI` | URI | _(1)_ | URI for the LaunchDarkly streaming service.
`baseUri` | `BASE_URI` | URI | _(1)_ | URI for the LaunchDarkly polling service for server-side SDKs.
`clientSideBaseUri` | `CLIENT_SIDE_BASE_URI` | URI | _(1)_ | URI for the LaunchDarkly polling service for client-side SDKs.
`exitOnError` | `EXIT_ON_ERROR` | Boolean | `false` | Close the Relay Proxy if it encounters any error during initialization.
`exitOnError` | `EXIT_ON_ERROR` | Boolean | `false` | Close the Relay Proxy if it encounters any error during initialization. The default behavior is that it will terminate (with a non-zero exit code) if the configuration options are completely invalid, or if there is an incorrect `AutoConfig` key, but will remain running if there is an error specific to one environment (such as an invalid SDK key). Setting this option to `true` makes it terminate in both cases.
`exitAlways` | `EXIT_ALWAYS` | Boolean | `false` | Close the Relay Proxy immediately after initializing all environments (do not start an HTTP server). _(2)_
`ignoreConnectionErrors` | `IGNORE_CONNECTION_ERRORS` | Boolean | `false` | Ignore any initial connectivity issues with LaunchDarkly. Best used when network connectivity is not reliable.
`port` | `PORT` | Number | `8030` | Port the Relay Proxy should listen on.
Expand Down
17 changes: 9 additions & 8 deletions internal/autoconfig/stream_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package autoconfig

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"regexp"
Expand Down Expand Up @@ -86,9 +87,9 @@ func NewStreamManager(
}

// Start causes the StreamManager to start trying to connect to the auto-config stream. The returned channel
// receives a value when the connection has either been made or permanently failed.
func (s *StreamManager) Start() <-chan struct{} {
readyCh := make(chan struct{}, 1)
// receives nil for a successful connection, or an error if it has permanently failed.
func (s *StreamManager) Start() <-chan error {
readyCh := make(chan error, 1)
go s.subscribe(readyCh)
return readyCh
}
Expand All @@ -100,19 +101,19 @@ func (s *StreamManager) Close() {
})
}

func (s *StreamManager) subscribe(readyCh chan<- struct{}) {
func (s *StreamManager) subscribe(readyCh chan<- error) {
req, _ := http.NewRequest("GET", s.uri, nil)
req.Header.Set("Authorization", string(s.key))
s.loggers.Infof(logMsgStreamConnecting, s.uri)

var readyOnce sync.Once
signalReady := func() { readyOnce.Do(func() { readyCh <- struct{}{} }) }
signalReady := func(err error) { readyOnce.Do(func() { readyCh <- err }) }

errorHandler := func(err error) es.StreamErrorHandlerResult {
if se, ok := err.(es.SubscriptionError); ok {
if se.Code == 401 || se.Code == 403 {
s.loggers.Error(logMsgBadKey)
signalReady()
signalReady(errors.New("invalid auto-configuration key"))
return es.StreamErrorHandlerResult{CloseNow: true}
}
s.loggers.Warnf(logMsgStreamHTTPError, se.Code)
Expand Down Expand Up @@ -147,11 +148,11 @@ func (s *StreamManager) subscribe(readyCh chan<- struct{}) {

if err != nil {
s.loggers.Errorf(logMsgStreamOtherError, err)
signalReady()
signalReady(err)
return
}

signalReady()
signalReady(nil)
s.consumeStream(stream)
}

Expand Down
14 changes: 13 additions & 1 deletion relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package relay
import (
"errors"
"net/http"
"os"
"time"

"github.com/launchdarkly/ld-relay/v6/config"
Expand Down Expand Up @@ -122,7 +123,18 @@ func newRelayInternal(c config.Config, options relayInternalOptions) (*Relay, er
0,
core.Loggers,
)
_ = r.autoConfigStream.Start()
autoConfigResult := r.autoConfigStream.Start()
go func() {
err := <-autoConfigResult
if err != nil {
// This channel only emits a non-nil error if it's an unrecoverable error, in which case
// Relay should quit. The ExitOnError option doesn't affect this, because a failure of
// auto-config is more serious than any environment-specific failure; Relay can't possibly
// do anything useful without a configuration. The StreamManager has already logged the
// error by this point, so we just need to quit.
os.Exit(1)
}
}()
}

if hasFileDataSource {
Expand Down

0 comments on commit ed578bd

Please sign in to comment.