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

Random error if multiple user send messages at a time. #153

Open
anoop012345 opened this issue Jul 26, 2023 · 2 comments
Open

Random error if multiple user send messages at a time. #153

anoop012345 opened this issue Jul 26, 2023 · 2 comments

Comments

@anoop012345
Copy link

anoop012345 commented Jul 26, 2023

This package is working fine but sometimes random errors are occur while making client . Most of time they occur when multiple users sends messages.

err : expected success or failure, got error in http://etherx.jabber.org/streams

err : unmarshal iq: expected element type iq but have

err : unmarshal features: expected element type features but have error

Please help me out to resolve these errors

@mdosch
Copy link
Collaborator

mdosch commented Feb 24, 2024

Can you provide an example where this happens? I just hacked together a little piece of code which sends 10 messages for 10 users in a short time and all worked well:

package main

import (
	"crypto/tls"
	"fmt"
	"log"
	"net"
	"strconv"
	"strings"

	"github.com/xmppo/go-xmpp"
	"salsa.debian.org/mdosch/xmppsrv"
)

func main() {
	user1 := REDACTED
	pw1 := REDACTED
	user2 := REDACTED
	pw2 := REDACTED
	user3 := REDACTED
	pw3 := REDACTED
	user4 := REDACTED
	pw4 := REDACTED
	user5 := REDACTED
	pw5 := REDACTED
	user6 := REDACTED
	pw6 := REDACTED
	user7 := REDACTED
	pw7 := REDACTED
	user8 := REDACTED
	pw8 := REDACTED
	user9 := REDACTED
	pw9 := REDACTED
	user10 := REDACTED
	pw10 := REDACTED
	srv, err := xmppsrv.LookupClient(strings.Split(user1, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server := net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS := false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options1 := xmpp.Options{
		Host:      server,
		User:      user1,
		Password:  pw1,
		Debug:     true,
		Mechanism: "SCRAM-SHA-1",
		NoTLS:     !directTLS,
		StartTLS:  !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user1, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	srv, err = xmppsrv.LookupClient(strings.Split(user2, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server = net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS = false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options2 := xmpp.Options{
		Host:      server,
		User:      user2,
		Password:  pw2,
		Debug:     true,
		Mechanism: "SCRAM-SHA-1",
		NoTLS:     !directTLS,
		StartTLS:  !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user2, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	srv, err = xmppsrv.LookupClient(strings.Split(user3, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server = net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS = false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options3 := xmpp.Options{
		Host:     server,
		User:     user3,
		Password: pw3,
		Debug:    true,
		// Mechanism: "SCRAM-SHA-1",
		NoTLS:    !directTLS,
		StartTLS: !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user3, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	srv, err = xmppsrv.LookupClient(strings.Split(user4, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server = net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS = false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options4 := xmpp.Options{
		Host:      server,
		User:      user4,
		Password:  pw4,
		Debug:     true,
		Mechanism: "SCRAM-SHA-1",
		NoTLS:     !directTLS,
		StartTLS:  !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user4, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	srv, err = xmppsrv.LookupClient(strings.Split(user5, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server = net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS = false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options5 := xmpp.Options{
		Host:      server,
		User:      user5,
		Password:  pw5,
		Debug:     true,
		Mechanism: "SCRAM-SHA-1",
		NoTLS:     !directTLS,
		StartTLS:  !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user5, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	srv, err = xmppsrv.LookupClient(strings.Split(user6, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server = net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS = false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options6 := xmpp.Options{
		Host:      server,
		User:      user6,
		Password:  pw6,
		Debug:     true,
		Mechanism: "SCRAM-SHA-1",
		NoTLS:     !directTLS,
		StartTLS:  !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user6, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	srv, err = xmppsrv.LookupClient(strings.Split(user7, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server = net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS = false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options7 := xmpp.Options{
		Host:      server,
		User:      user7,
		Password:  pw7,
		Debug:     true,
		Mechanism: "SCRAM-SHA-1",
		NoTLS:     !directTLS,
		StartTLS:  !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user7, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	srv, err = xmppsrv.LookupClient(strings.Split(user8, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server = net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS = false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options8 := xmpp.Options{
		Host:     server,
		User:     user8,
		Password: pw8,
		Debug:    true,
		// Mechanism: "SCRAM-SHA-1",
		NoTLS:    !directTLS,
		StartTLS: !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user8, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	srv, err = xmppsrv.LookupClient(strings.Split(user9, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server = net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS = false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options9 := xmpp.Options{
		Host:      server,
		User:      user9,
		Password:  pw9,
		Debug:     true,
		Mechanism: "SCRAM-SHA-1",
		NoTLS:     !directTLS,
		StartTLS:  !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user9, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	srv, err = xmppsrv.LookupClient(strings.Split(user10, "@")[1])
	if err != nil {
		log.Fatal(err)
	}
	server = net.JoinHostPort(srv[0].Target, fmt.Sprint(srv[0].Port))
	directTLS = false
	if srv[0].Type == "xmpps-client" {
		directTLS = true
	}
	options10 := xmpp.Options{
		Host:      server,
		User:      user10,
		Password:  pw10,
		Debug:     true,
		Mechanism: "SCRAM-SHA-1",
		NoTLS:     !directTLS,
		StartTLS:  !directTLS,
		TLSConfig: &tls.Config{
			ServerName: strings.Split(user10, "@")[1],
			NextProtos: []string{"xmpp-client"},
		},
	}
	conn1, err := options1.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	conn2, err := options2.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	conn3, err := options3.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	conn4, err := options4.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	conn5, err := options5.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	conn6, err := options6.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	conn7, err := options7.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	conn8, err := options8.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	conn9, err := options9.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	conn10, err := options10.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	for i := 1; i < 11; i++ {
		msg := "Test " + strconv.Itoa(i)
		conn1.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
		conn2.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
		conn3.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
		conn4.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
		conn5.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
		conn6.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
		conn7.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
		conn8.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
		conn9.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
		conn10.Send(xmpp.Chat{Remote: "REDACTED", Type: "chat", Text: msg})
	}
}

@mdosch
Copy link
Collaborator

mdosch commented May 6, 2024

@anoop012345 any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants