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

Can't reliably get PubSub - "no available client found" #244

Open
nicoroy2561 opened this issue Mar 28, 2024 · 0 comments
Open

Can't reliably get PubSub - "no available client found" #244

nicoroy2561 opened this issue Mar 28, 2024 · 0 comments
Assignees

Comments

@nicoroy2561
Copy link

nicoroy2561 commented Mar 28, 2024

I keep getting the "no available client found" error when calling pubsub, err = client.NewPubSub() on client = cache.NewEmbeddedClient(). It seems to seldomly work - I managed to get it to work like 1/10 times.


22:36:17.574 [INFO] Olric 0.5.4 on linux/amd64 go1.22.0
 
23:36:17.574 [INFO] Join completed. Synced with 1 initial nodes
 
23:36:17.575 [INFO] Memberlist bindAddr: 10.244.0.88, bindPort: 3322
 
23:36:17.575 [INFO] Cluster coordinator: 10.244.0.38:3320
 
23:36:17.575 [INFO] Node name in the cluster: 10.244.0.88:3320
 
23:36:17.575 [INFO] Olric bindAddr: 10.244.0.88, bindPort: 3320
 
23:36:17.575 [INFO] Replication count is 1
 
23:36:17.575 [INFO] Node joined: 10.244.0.38:3320
 
23:36:17.587 [INFO] Routing table has been pushed by 10.244.0.38:3320
 
23:36:17.588 pubsub error no available client found

Code I'm using is the one from the base example with some custom kubernetes discovery setup:

func Init(discovery *k8s.K8sDiscovery) bool {
	discoveryAdapter, err := newK8sAdapter(discovery)
	if err != nil {
		log.Fatalln("adapter error:", err)
	}

	// create a new Olric configuration
	cfg := config.New("lan") // default configuration
	cfg.ReplicationMode = config.SyncReplicationMode
	cfg.ServiceDiscovery = map[string]interface{}{"plugin": discoveryAdapter} //https://gist.github.com/derekperkins/8f5232d897ccf5a20691a1556574cfce
	cfg.DMaps.EvictionPolicy = config.LRUEviction                             //
	cfg.DMaps.MaxInuse = 50_000_000                                           // 50 MB

	cfg.LogLevel = "INFO"
	cfg.LogVerbosity = 3 // at least 2 is recommended; https://github.com/buraksezer/olric/blob/master/config/config.go#L102

	// this wait group is used to block the main goroutine until the embedded client is ready
	wg := sync.WaitGroup{}
	wg.Add(1)
	cfg.Started = func() { wg.Done() }

	// create the actual Olric instance
	cache, err = olric.New(cfg)
	if err != nil {
		log.Println("error creating cache from config:", err)
		return false
	}

	// start the instance, which triggers the k8s service discovery and forms the cluster
	go func() {
		if err := cache.Start(); err != nil {
			panic("error starting:" + err.Error())
		}
	}()

	// wait for the cluster to be ready before continuing
	wg.Wait()

	client = cache.NewEmbeddedClient()
	if client == nil {
		log.Fatalln("client nil")
	}

	pubsub, err = client.NewPubSub()
	if err != nil {
		log.Fatalln("pubsub error", err)
	}
	return true
}

Any suggestions on what I might be doing wrong here?

@buraksezer buraksezer self-assigned this May 10, 2024
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

2 participants