Skip to content

Commit

Permalink
chore: Add a warning message if the waitFor duration is too long (#148)
Browse files Browse the repository at this point in the history
This adds a warning-level message and we make sure the test still runs

---------

Co-authored-by: Casey Waldren <[email protected]>
  • Loading branch information
louis-launchdarkly and cwaldren-ld authored May 10, 2024
1 parent e2f582e commit 68e3440
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ldclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import (
// Version is the SDK version.
const Version = internal.SDKVersion

// highWaitForSeconds is the initialization wait time threshold that we will log a warning message
const highWaitForSeconds = 60

const (
boolVarFuncName = "LDClient.BoolVariation"
intVarFuncName = "LDClient.IntVariation"
Expand Down Expand Up @@ -327,6 +330,14 @@ func MakeCustomClient(sdkKey string, config Config, waitFor time.Duration) (*LDC
if waitFor > 0 && client.dataSource != datasource.NewNullDataSource() {
loggers.Infof("Waiting up to %d milliseconds for LaunchDarkly client to start...",
waitFor/time.Millisecond)

// If you use a long duration and wait for the timeout, then any network delays will cause
// your application to wait a long time before continuing execution.
if waitFor.Seconds() > highWaitForSeconds {
loggers.Warnf("Client was created was with a timeout greater than %d. "+
"We recommend a timeout of less than %d seconds", highWaitForSeconds, highWaitForSeconds)
}

timeout := time.After(waitFor)
for {
select {
Expand Down

0 comments on commit 68e3440

Please sign in to comment.