You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a simple HTTP server with an endpoint (GET http://localhost:8099/keygen) to generate a key. The handler for this endpoint invokes the GenerateKey func from the emitter-io client.
I have bench-marked this API endpoint, and found that the invocations to GenerateKey results in a deadlock state when I attempt to maintain a set number of concurrent requests for a duration of time. The problem is easily reproducible with 50 concurrent requests over a 2 minute period. Note that the problem is not evident when running a single keygen request at a time.
Here is a sample program to reproduce the deadlock. Ensure to set appropriate values for the SECRET_KEY, BROKER_HOST and BROKER_PORT constants.
Start it with the -race flag: go run -race main.go
package main
import (
"fmt"
"io"
"log"
"net/http"
emitter "github.com/emitter-io/go/v2"
uuid "github.com/satori/go.uuid"
)
const (
SECRET_KEY = "<your_secret_key>"
BROKER_HOST = "172.16.238.16"
BROKER_PORT = "8080"
)
func main() {
// Create the client and connect to the broker
c, err := emitter.Connect(fmt.Sprintf("tcp://%s:%s", BROKER_HOST, BROKER_PORT),
func(_ *emitter.Client, msg emitter.Message) {
log.Fatalf("[emitter] -> [B] received: '%s' topic: '%s'\n", msg.Payload(), msg.Topic())
})
if err != nil {
log.Panic(err)
}
id := c.ID()
fmt.Println("[emitter] -> [B] my name is " + id)
// HTTP server
keygenHandler := func(w http.ResponseWriter, req *http.Request) {
channelId := uuid.NewV4()
var key string
key, err = c.GenerateKey(SECRET_KEY, fmt.Sprintf("channel/%s/", channelId), "r", 600)
if err != nil {
log.Panic(err)
}
fmt.Println(key)
io.WriteString(w, key)
}
http.HandleFunc("/keygen", keygenHandler)
log.Fatal(http.ListenAndServe(":8099", nil))
}
Sample output in console. The data race warning is displayed and the client stopped processing any GenerateKey requests. You have to restart the application for the emitter to process keygen requests again once it got into this state.
I have a simple HTTP server with an endpoint (
GET http://localhost:8099/keygen
) to generate a key. The handler for this endpoint invokes theGenerateKey
func from the emitter-io client.I have bench-marked this API endpoint, and found that the invocations to GenerateKey results in a deadlock state when I attempt to maintain a set number of concurrent requests for a duration of time. The problem is easily reproducible with 50 concurrent requests over a 2 minute period. Note that the problem is not evident when running a single keygen request at a time.
Here is a sample program to reproduce the deadlock. Ensure to set appropriate values for the
SECRET_KEY
,BROKER_HOST
andBROKER_PORT
constants.Start it with the
-race
flag:go run -race main.go
Sample output in console. The data race warning is displayed and the client stopped processing any
GenerateKey
requests. You have to restart the application for the emitter to process keygen requests again once it got into this state.The text was updated successfully, but these errors were encountered: