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

SASL handshake failed #1362

Open
j285627868 opened this issue Jan 9, 2025 · 1 comment
Open

SASL handshake failed #1362

j285627868 opened this issue Jan 9, 2025 · 1 comment

Comments

@j285627868
Copy link

hi guys,

When I connect to the Kafka server, I receive the following error message:

could not successfully authenticate to 192.107.0.1:9200 with SASL: SASL handshake failed: [34] Illegal SASL State: the request is not valid given the current SASL state

The code for the connection is as follows:

func NewClient() *kafka.Reader {
	conf := config.Cfg.Kafka
	groupTopics := strings.Join(conf.Topic, "-")
	consumerGroup := fmt.Sprintf("%s_xxx_%s_%d", groupTopics, "group", conf.Node)
	mechanism, errM := scram.Mechanism(scram.SHA256, conf.Username, conf.Password)
	if errM != nil {
		panic(errM)
	}
	return kafka.NewReader(kafka.ReaderConfig{
		Brokers:     conf.Addrs,
		GroupID:     consumerGroup,
		GroupTopics: conf.Topic,
		MaxBytes:    10e6, // 10MB
		Dialer: &kafka.Dialer{
			Timeout:       10 * time.Second,
			DualStack:     true,
			SASLMechanism: mechanism,
		},
	})
}
func (k *KAFKA) Run() error {
	var err error
	var msg kafka.Message
	ctx := context.Background()
	for {
		msg, err = k.Client.FetchMessage(ctx)
		if err != nil {
                }
}

May I ask where the problem lies? thank you.

@petedannemann
Copy link
Contributor

This error is usually thrown when SASL is not configured on the broker correctly. Can you check your broker SASL configuration and broker logs?

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