feat: add WithDisablePolling and WithSynchronousFetchOnInitialisation options - #268
Closed
sukesh2000 wants to merge 2 commits into
Closed
feat: add WithDisablePolling and WithSynchronousFetchOnInitialisation options#268sukesh2000 wants to merge 2 commits into
sukesh2000 wants to merge 2 commits into
Conversation
Author
|
Closing this as well. See the discussion in #267. Thanks. |
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.
About the changes
Adds two new config options available in other Unleash SDKs (Node, Java) but not yet present in the Go v5 SDK:
WithDisablePolling(true)— stops the client from polling the Unleash server after the initial startup. The client serves whatever state was loaded from backup storage or fetched on initialisation. Intended for serverless/lambda environments, air-gapped deployments, and CI setups where toggle state only changes on redeploy.WithSynchronousFetchOnInitialisation(true)— makesNewClientblock until the first fetch completes, so toggles are available immediately on return without callingWaitForReady(). Subsequent polling (if enabled) continues as normal in the background.The two options compose:
disablePollingsynchronousFetchfalsefalsefalsetrueNewClientblocks on first fetch, goroutine skips the leading fetch, polls normallytruefalsetruetrueNewClientblocks on first fetch, ready fires, no polling goroutineIn all four cases, if the initial fetch fails the client falls back to whatever is in backup storage rather than returning an error, and
readystill fires so the application is not blocked.Closes #185
Important files
config.go— the two newWith*option funcs and their doc comments, start here for the public API shaperepository.go— core logic: the four-quadrant behaviour matrix, the skip-leading-fetch guard insync()that prevents a double-fetch whensynchronousFetchalready succeeded, and guardedClose()for the no-goroutine pathclient_test.go— client-level integration tests for all four flag combinations plus the streaming interactionDiscussion points
WithSynchronousFetchOnInitialisationhas no effect in streaming mode.In v5, the synchronous fetch path is guarded by
!repo.isStreaming, so streaming mode is unaffected. Streaming starts the sync goroutine as normal.disablePolling=trueis overridden by streaming.When
isStreaming=true, thedisablePollingflag is ignored — the sync goroutine always starts for streaming.Close()correctly uses the blocking shutdown path when streaming is active.Close()withdisablePolling=true(non-streaming) does not start or wait on a goroutine.r.close,r.closed, andr.refreshTickerare only allocated when the goroutine starts.Close()is guarded with nil checks and skips the blocking<-r.closedwait, so there is no deadlock.Failover from sync fetch failure retries immediately.
When
synchronousFetch=trueand the initial fetch fails, the polling goroutine's leading-fetch condition is!r.options.synchronousFetch || !r.isReady. This ensures the goroutine retries immediately rather than waiting a fullrefreshIntervalbefore the client becomes ready.