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

radix.NewCluster got err: NOAUTH Authentication required. #276

Closed
bigBron opened this issue May 8, 2021 · 3 comments
Closed

radix.NewCluster got err: NOAUTH Authentication required. #276

bigBron opened this issue May 8, 2021 · 3 comments

Comments

@bigBron
Copy link

bigBron commented May 8, 2021

I can confirm that the configuration is correct and the same configuration can connect to the cluster using go-redis.

Locate where the error occurred:

radix/cluster.go

Lines 203 to 208 in edd71cc

if err := c.Sync(); err != nil {
for _, p := range c.pools {
p.Close()
}
return nil, err
}

ref: kataras/neffos#55

@nussjustin
Copy link
Contributor

The cluster you are trying to connect to requires authentication, but you didn't provide any.

You can try something like this to authenticate each connection in the cluster:

cluster, err := radix.NewCluster(cfg.Clusters, radix.ClusterPoolFunc(func(network, addr string) (Client, error) {
	return radix.NewPool(network, addr, 4, radix.PoolConnFunc(func(network, addr string) (Client, error) {
		return radix.Dial(network, addr, radix.DialAuthPass(cfg.Password))
	}))
}))
if err != nil {
	// maybe an
	// ERR This instance has cluster support disabled
	return nil, err
}

Or you can put the password into the addresses passed to NewClusters either as parameter (redis://127.0.0.1:6379/?password=bla) or before the host (redis://:[email protected]:6379).

Also looking at the code linked in the referenced issue, I'm confused about the cluster usage. The code creates a *radix.Cluster instance but then creates another *radix.Pool that just creates connections from random cluster members? Why not just use the *Cluster instance directly.

If you change the StackExchange.Pool field from type *radix.Pool to radix.Client (which *radix.Pool implements) you can simplify the creation of the StackExchange instance like this:

var client radix.Client
if len(cfg.Clusters) > 0 {
	cluster, err := radix.NewCluster(cfg.Clusters, radix.ClusterPoolFunc(func(network, addr string) (Client, error) {
		return radix.NewPool(network, addr, 4, radix.PoolConnFunc(func(network, addr string) (Client, error) {
			return radix.Dial(network, addr, radix.DialAuthPass(cfg.Password))
		}))
	}))
	if err != nil {
		// maybe an
		// ERR This instance has cluster support disabled
		return nil, err
	}
	client = cluster
} else {
	pool, err := radix.NewPool("", "", cfg.MaxActive, radix.PoolConnFunc(connFunc))
	if err != nil {
		return nil, err
	}
	client = pool
}

exc := &StackExchange{
	pool:     client,
	connFunc: connFunc,
	// If you are using one redis server for multiple nefos servers,
	// use a different channel for each neffos server.
	// Otherwise a message sent from one server to all of its own clients will go
	// to all clients of all nefos servers that use the redis server.
	// We could use multiple channels but overcomplicate things here.
	channel: channel,

	subscribers:   make(map[*neffos.Conn]*subscriber),
	addSubscriber: make(chan *subscriber),
	delSubscriber: make(chan closeAction),
	subscribe:     make(chan subscribeAction),
	unsubscribe:   make(chan unsubscribeAction),
}

There should be no difference in the behavior. Only the number of connections to the nodes should be reduced (since the cluster keeps 4 connections to each node by default, even if you only use the cluster for retrieving the topology information, plus the MaxActive connections from your pool, which would go away if you use the cluster directly)

Also by using the radix.Cluster type you get automatically handling of failovers, topology changes and sharding. Using a normal radix.Pool you don't get any of these. And while these may not all be necessary (since you only use the PUBLISH) command, the radix.Cluster type gives them to you for free.

@bigBron
Copy link
Author

bigBron commented May 9, 2021

Cool, your thinking is very clear. Thank you very much for your reply. I will sort out your use cases and try them out.

@bigBron
Copy link
Author

bigBron commented May 9, 2021

The problem has been solved. I have reimplemented the interface according to your instructions, and everything runs normally. Thank you @nussjustin.

@bigBron bigBron closed this as completed May 9, 2021
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