xmppo / go-xmpp

Go XMPP Library (From Yasuhiro Matsumoto and based on the code from Russ Cox)
https://golang.org/
BSD 3-Clause "New" or "Revised" License
526 stars 170 forks source link

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

Open anoop012345 opened 1 year ago

anoop012345 commented 1 year ago

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 commented 6 months ago

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 commented 4 months ago

@anoop012345 any news?