Skip to content

Commit

Permalink
Fixes blevesearch#1873 Adding timeout in the search handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Likith101 committed Nov 14, 2023
1 parent 0c31cd2 commit 7226997
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions http/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"io"
"net/http"
"strconv"
"time"

"github.com/blevesearch/bleve/v2"
Expand Down Expand Up @@ -89,12 +88,12 @@ func (h *SearchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if timeoutStr == "" {
ctx = context.Background()
} else {
timeout, err := strconv.Atoi(timeoutStr)
timeout, err := time.ParseDuration(timeoutStr)
if err != nil {
showError(w, req, fmt.Sprintf("error parsing timeout value: %v", err), 400)
return
}
ctx, _ = context.WithTimeout(context.Background(), time.Duration(timeout)*time.Millisecond)
ctx, _ = context.WithTimeout(context.Background(), timeout)
}

// execute the query
Expand Down

0 comments on commit 7226997

Please sign in to comment.