From 6aab4fb44bda5119c69baeaed798551d0552f5d9 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Wed, 8 Nov 2023 20:42:36 +0800 Subject: [PATCH] 120 timeout if only one upstream --- main.go | 4 ++++ process.go | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 1070353..86f8f5f 100644 --- a/main.go +++ b/main.go @@ -133,6 +133,10 @@ func main() { shouldResponse := index == len(upstreams)-1 + if len(upstreams) == 1 { + upstream.Timeout = 120 + } + err = processRequest(c, &upstream, &record, shouldResponse) if err != nil { log.Println("Error from upstream", upstream.Endpoint, "should retry", err) diff --git a/process.go b/process.go index 5622437..57ef97f 100644 --- a/process.go +++ b/process.go @@ -62,16 +62,16 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s // set timeout, default is 60 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 { timeout = 5 * time.Second } if len(inBody) > 1024*128 { timeout = 20 * time.Second } + if upstream.Timeout > 0 { + // convert upstream.Timeout(second) to nanosecond + timeout = time.Duration(upstream.Timeout) * time.Second + } // timeout out request go func() {