Repository navigation
Conversation
GetAllFlagsState returned before its deferred Close when MakeCustomClient failed. After a timeout, the SDK still returns a client, and that client kept its stream connection open and retried in the background. Since go-server-sdk 7.16 (#873), a rejected SDK key also gives a timeout, so each failed import or sync left one more client that retried for the life of the dev server. If MakeCustomClient returns an error and a client, close the client. The error and its message do not change. Co-authored-by: rniebla <rniebla@launchdarkly.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirements
Related issues
Follow-up to #873, which updated go-server-sdk from 7.13.4 to 7.18.0.
Describe the solution you've provided
The dev server creates an SDK client in
internal/dev_server/adapters/sdk.gofor each project import and sync. Ifld.MakeCustomClientreturned an error,GetAllFlagsStatereturned before its deferredClose. After a timeout, the SDK still returns a client. That client kept its stream connection open and retried in the background.Since go-server-sdk 7.16 (#873), a rejected SDK key (HTTP 401 or 403) also gives a timeout after the full
--sdk-init-timeout. The failed client then retries with a backoff of 5 minutes to 1 hour. Each failed import or sync left one more client that retried until the dev server stopped. The same leak already existed for a plain timeout.Now, if
MakeCustomClientreturns an error and a client,GetAllFlagsStatecloses the client before it returns. The error and its message do not change:unable to get source flags from LD SDK: timeout encountered waiting for LaunchDarkly client initialization.streamingSdkhas a new unexportedloggerfield. Tests use it to read the SDK log. Production code does not set it, so the SDK log output does not change.The new test
TestGetAllFlagsStateClosesClientWhenInitFailsstarts a local stream server with a 500 ms initialization timeout. It makes sure that the client closes in three cases:Closing LaunchDarkly client.GetAllFlagsStatereturns.All three cases fail without the fix and pass with it. The test passed five times in a row with
-race.go build,go test ./..., and golangci-lint v1.63.4 pass.I also ran the built binary with
ldcli dev-server startagainst a fake stream that rejects the SDK key. The import fails with HTTP 500 after 3 seconds and the same message as before. The dev-server log now has oneClosing LaunchDarkly clientline after the timeout. Before this change, it had none.Describe alternatives you've considered
The dev server could restore the earlier fast failure for a rejected key. To do this, it can watch the data source status and stop early on 401 or 403. That changes the error behavior, so it is not in this pull request.
Additional context
LDClient.Closeonly logs and stops the data system. It is safe to call on a client that did not initialize.