120 timeout if only one upstream
This commit is contained in:
4
main.go
4
main.go
@@ -133,6 +133,10 @@ func main() {
|
|||||||
|
|
||||||
shouldResponse := index == len(upstreams)-1
|
shouldResponse := index == len(upstreams)-1
|
||||||
|
|
||||||
|
if len(upstreams) == 1 {
|
||||||
|
upstream.Timeout = 120
|
||||||
|
}
|
||||||
|
|
||||||
err = processRequest(c, &upstream, &record, shouldResponse)
|
err = processRequest(c, &upstream, &record, shouldResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error from upstream", upstream.Endpoint, "should retry", err)
|
log.Println("Error from upstream", upstream.Endpoint, "should retry", err)
|
||||||
|
|||||||
@@ -62,16 +62,16 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
|
|||||||
|
|
||||||
// set timeout, default is 60 second
|
// set timeout, default is 60 second
|
||||||
timeout := 60 * time.Second
|
timeout := 60 * time.Second
|
||||||
if upstream.Timeout > 0 {
|
|
||||||
// convert upstream.Timeout(second) to nanosecond
|
|
||||||
timeout = time.Duration(upstream.Timeout) * time.Second
|
|
||||||
}
|
|
||||||
if requestBodyOK == nil && requestBody.Stream {
|
if requestBodyOK == nil && requestBody.Stream {
|
||||||
timeout = 5 * time.Second
|
timeout = 5 * time.Second
|
||||||
}
|
}
|
||||||
if len(inBody) > 1024*128 {
|
if len(inBody) > 1024*128 {
|
||||||
timeout = 20 * time.Second
|
timeout = 20 * time.Second
|
||||||
}
|
}
|
||||||
|
if upstream.Timeout > 0 {
|
||||||
|
// convert upstream.Timeout(second) to nanosecond
|
||||||
|
timeout = time.Duration(upstream.Timeout) * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
// timeout out request
|
// timeout out request
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user