Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to close the client with feature flag poller #28

Open
zaynetro opened this issue Jan 19, 2024 · 0 comments
Open

Impossible to close the client with feature flag poller #28

zaynetro opened this issue Jan 19, 2024 · 0 comments

Comments

@zaynetro
Copy link
Contributor

Hi! It is impossible to close posthog.Client when feature flags are enabled and no requests to get all flags were made.

What happens:

  1. FeatureFlagsPoller.run starts
  2. Execution is blocked on poller.loaded <- false in fetchNewFeatureFlags because nobody reads from that channel
  3. Infinite loop never starts so <-poller.shutdown is never consumed hence blocking Client.Close method here.
  4. Things work if we GetFeatureFlags at least once. It starts reading poller.loaded channel here

Minimal reproduction example:

package main

import (
	"fmt"
	"os"

	"github.com/posthog/posthog-go"
)

func main() {
	client, err := posthog.NewWithConfig("123", posthog.Config{
		PersonalApiKey: "123",
	})
	if err != nil {
		fmt.Println("could not initialize posthog client", err)
		os.Exit(1)
	}

	// NOTE: Uncomment for things to start working
	// flags, err := client.GetFeatureFlags()
	// fmt.Println("Flags", flags, err)

	fmt.Println("Trying to close the client...")
	if err := client.Close(); err != nil {
		fmt.Println("Failed to close:", err)
	}

	fmt.Println("Client closed.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant