-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
[BUG] Broadcast deadlocks when concurrency #59
Labels
bug
Something isn't working
Comments
package main
import (
"context"
"fmt"
"github.com/kataras/neffos"
"github.com/kataras/neffos/gorilla"
"strconv"
"testing"
"time"
)
var (
handler = neffos.WithTimeout{
Namespaces: neffos.Namespaces{
"test": neffos.Events{
neffos.OnNamespaceConnected: func(c *neffos.NSConn, msg neffos.Message) error {
fmt.Println("成功链接:", c.Conn.ID())
c.Emit("ch", []byte(""))
return nil
},
neffos.OnNamespaceDisconnect: func(c *neffos.NSConn, msg neffos.Message) error {
fmt.Println("断开链接:", c.Conn.ID())
return nil
},
neffos.OnRoomJoined: func(c *neffos.NSConn, msg neffos.Message) error {
fmt.Println("OnRoomJoined:---", msg)
return nil
},
neffos.OnRoomLeft: func(c *neffos.NSConn, msg neffos.Message) error {
fmt.Println("OnRoomLeft:---", msg)
return nil
},
"ch": func(conn *neffos.NSConn, message neffos.Message) error {
fmt.Println("ch--------", string(message.Body))
return nil
},
},
},
}
)
// 1
func TestWs(t *testing.T) {
// 直接使用大猩猩的dialer
dialer := gorilla.DefaultDialer
fmt.Println("-- Running...")
go connect(dialer, "ws://127.0.0.1:8090/e?id=a")
select {}
}
// 30
func TestA(t *testing.T) {
dialer := gorilla.DefaultDialer
fmt.Println("-- Running...")
for i := 0; i < 30; i++ {
go connect(dialer, "ws://127.0.0.1:8090/e?id="+strconv.Itoa(i))
}
select {}
}
func connect(dialer neffos.Dialer, url string) {
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(10*time.Second))
defer cancel()
fmt.Println(url)
client, err := neffos.Dial(ctx, dialer, url, handler)
if err != nil {
fmt.Printf("connection failure: %v\n", err)
return
}
if client.ID == "" {
panic("CLIENT'S ID IS EMPTY.\n DIAL NOW SHOULD BLOCK UNTIL ID IS FILLED(ACK) AND UNTIL SERVER'S CONFIRMATION")
}
ctxConnect, cancelConnect := context.WithDeadline(context.Background(), time.Now().Add(25*time.Second))
defer cancelConnect()
var c *neffos.NSConn
c, err = client.Connect(ctxConnect, "test")
if err != nil {
fmt.Println("链接到namespace err:", err)
return
}
if c.Conn.ID() == "" {
panic("CLIENT'S CONNECTION ID IS EMPTY.\nCONNECT SHOULD BLOCK UNTIL ID IS FILLED(ACK) AND UNTIL SERVER'S CONFIRMATION TO NAMESPACE CONNECTION")
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I found in the actual application that the Broadcast() method will cause a deadlock
To Reproduce
Steps to reproduce the behavior:
nsConn
is disconnected, it will causeServer.Broadcast()
internal blocking'' when broadcasting a message on thewebsocket.OnNamespaceDisconnect
orwebsocket.OnRoomLeft
eventThe text was updated successfully, but these errors were encountered: