diff --git a/internal/distributed/proxy/httpserver/constant.go b/internal/distributed/proxy/httpserver/constant.go index a8e1a185ad..7b68cfad7c 100644 --- a/internal/distributed/proxy/httpserver/constant.go +++ b/internal/distributed/proxy/httpserver/constant.go @@ -17,8 +17,6 @@ package httpserver import ( - "time" - "github.com/milvus-io/milvus/pkg/v2/util/metric" ) @@ -120,7 +118,6 @@ const ( HTTPHeaderAllowInt64 = "Accept-Type-Allow-Int64" HTTPHeaderDBName = "DB-Name" HTTPHeaderRequestTimeout = "Request-Timeout" - HTTPDefaultTimeout = 30 * time.Second HTTPReturnCode = "code" HTTPReturnMessage = "message" HTTPReturnData = "data" diff --git a/internal/distributed/proxy/httpserver/timeout_middleware.go b/internal/distributed/proxy/httpserver/timeout_middleware.go index 6e35c6f3e1..33a6ca421b 100644 --- a/internal/distributed/proxy/httpserver/timeout_middleware.go +++ b/internal/distributed/proxy/httpserver/timeout_middleware.go @@ -30,6 +30,7 @@ import ( mhttp "github.com/milvus-io/milvus/internal/http" "github.com/milvus-io/milvus/pkg/v2/util/merr" + "github.com/milvus-io/milvus/pkg/v2/util/paramtable" ) func defaultResponse(c *gin.Context) { @@ -58,7 +59,6 @@ func (p *BufferPool) Put(buf *bytes.Buffer) { // Timeout struct type Timeout struct { - timeout time.Duration handler gin.HandlerFunc response gin.HandlerFunc } @@ -154,7 +154,6 @@ func checkWriteHeaderCode(code int) { func timeoutMiddleware(handler gin.HandlerFunc) gin.HandlerFunc { t := &Timeout{ - timeout: mhttp.HTTPDefaultTimeout, handler: handler, response: defaultResponse, } @@ -164,9 +163,10 @@ func timeoutMiddleware(handler gin.HandlerFunc) gin.HandlerFunc { defer cancel() gCtx.Request = gCtx.Request.WithContext(topCtx) + timeout := paramtable.Get().HTTPCfg.RequestTimeoutMs.GetAsDuration(time.Millisecond) timeoutSecond, err := strconv.ParseInt(gCtx.Request.Header.Get(mhttp.HTTPHeaderRequestTimeout), 10, 64) if err == nil { - t.timeout = time.Duration(timeoutSecond) * time.Second + timeout = time.Duration(timeoutSecond) * time.Second } finish := make(chan struct{}, 1) panicChan := make(chan interface{}, 1) @@ -209,7 +209,7 @@ func timeoutMiddleware(handler gin.HandlerFunc) gin.HandlerFunc { tw.FreeBuffer() bufPool.Put(buffer) - case <-time.After(t.timeout): + case <-time.After(timeout): gCtx.Abort() tw.mu.Lock() defer tw.mu.Unlock() diff --git a/internal/http/constant.go b/internal/http/constant.go index cf0e0c988e..38766a2f81 100644 --- a/internal/http/constant.go +++ b/internal/http/constant.go @@ -1,13 +1,8 @@ package http -import ( - "time" -) - const ( HTTPHeaderAllowInt64 = "Accept-Type-Allow-Int64" HTTPHeaderRequestTimeout = "Request-Timeout" - HTTPDefaultTimeout = 30 * time.Second HTTPReturnCode = "code" HTTPReturnMessage = "message" HTTPReturnData = "data" diff --git a/pkg/util/paramtable/http_param.go b/pkg/util/paramtable/http_param.go index 66a51beafe..d469a830ba 100644 --- a/pkg/util/paramtable/http_param.go +++ b/pkg/util/paramtable/http_param.go @@ -22,7 +22,7 @@ type httpConfig struct { Port ParamItem `refreshable:"false"` AcceptTypeAllowInt64 ParamItem `refreshable:"true"` EnablePprof ParamItem `refreshable:"false"` - RequestTimeoutMs ParamItem `refreshable:"false"` + RequestTimeoutMs ParamItem `refreshable:"true"` } func (p *httpConfig) init(base *BaseTable) { @@ -71,4 +71,13 @@ func (p *httpConfig) init(base *BaseTable) { Export: true, } p.EnablePprof.Init(base.mgr) + + p.RequestTimeoutMs = ParamItem{ + Key: "proxy.http.requestTimeoutMs", + DefaultValue: "30000", + Version: "2.5.10", + Doc: "default restful request timeout duration in milliseconds", + Export: false, + } + p.RequestTimeoutMs.Init(base.mgr) }