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 implemented TTS for my application, everything is fine when sending one request at a time, but when running multiple requests simultaneously, I encounter a signal: segmentation fault error, and here is my code.
model, err := whisper.New(flags.GetModel())
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
http.HandleFunc("/whisper", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost {
file, handler, err := r.FormFile("file")
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
defer file.Close()
result := make(chan map[string]interface{})
go func() {
defer model.Close()
data, err := controller.Process(model, file, handler.Filename, false, flags)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
result <- data
}()
//Send result to client
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(<-result); err != nil {
http.Error(w, "Error encoding JSON", http.StatusInternalServerError)
}
} else {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
})
From a quick glance, it looks like you're closing the model after the first request. You should be reusing the model (thread safe) but each context can only be used by a single request (at a time). Depending on the type / level of concurrency you are using, you may be better off using a worker pattern to do the transcription... as things will get very slow if you try to use more threads than your system has available.
I have implemented TTS for my application, everything is fine when sending one request at a time, but when running multiple requests simultaneously, I encounter a signal: segmentation fault error, and here is my code.
The text was updated successfully, but these errors were encountered: