Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c4ca4af8
authored
Mar 05, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Prevent resource leaks by adding body close in stream handlers
parent
d6472145
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
4 deletions
+7
-4
relay/channel/claude/relay-claude.go
+1
-1
relay/channel/gemini/relay-gemini.go
+1
-1
relay/channel/openai/relay-openai.go
+1
-1
relay/helper/stream_scanner.go
+4
-1
No files found.
relay/channel/claude/relay-claude.go
View file @
c4ca4af8
...
...
@@ -506,7 +506,7 @@ func ClaudeStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.
}
}
helper
.
Done
(
c
)
resp
.
Body
.
Close
()
//
resp.Body.Close()
return
nil
,
usage
}
...
...
relay/channel/gemini/relay-gemini.go
View file @
c4ca4af8
...
...
@@ -534,7 +534,7 @@ func GeminiChatStreamHandler(c *gin.Context, resp *http.Response, info *relaycom
}
}
helper
.
Done
(
c
)
resp
.
Body
.
Close
()
//
resp.Body.Close()
return
nil
,
usage
}
...
...
relay/channel/openai/relay-openai.go
View file @
c4ca4af8
...
...
@@ -249,7 +249,7 @@ func OaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rel
helper
.
Done
(
c
)
resp
.
Body
.
Close
()
//
resp.Body.Close()
return
nil
,
usage
}
...
...
relay/helper/stream_scanner.go
View file @
c4ca4af8
...
...
@@ -15,7 +15,10 @@ import (
)
func
StreamScannerHandler
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
,
dataHandler
func
(
data
string
)
bool
)
{
if
resp
==
nil
{
return
}
defer
resp
.
Body
.
Close
()
streamingTimeout
:=
time
.
Duration
(
constant
.
StreamingTimeout
)
*
time
.
Second
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"o1"
)
||
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"o3"
)
{
// twice timeout for thinking model
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment