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
ac9df0c1
authored
May 28, 2025
by
creamlike1024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: pingerCtx 泄漏
parent
ef21119a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
relay/channel/api_request.go
+6
-5
No files found.
relay/channel/api_request.go
View file @
ac9df0c1
...
@@ -122,11 +122,13 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
...
@@ -122,11 +122,13 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
var
pingerWg
sync
.
WaitGroup
var
pingerWg
sync
.
WaitGroup
if
info
.
IsStream
{
if
info
.
IsStream
{
helper
.
SetEventStreamHeaders
(
c
)
helper
.
SetEventStreamHeaders
(
c
)
pingInterval
:=
time
.
Duration
(
generalSettings
.
PingIntervalSeconds
)
*
time
.
Second
var
pingerCtx
context
.
Context
pingerCtx
,
stopPinger
=
context
.
WithCancel
(
c
.
Request
.
Context
())
if
pingEnabled
{
if
pingEnabled
{
pingInterval
:=
time
.
Duration
(
generalSettings
.
PingIntervalSeconds
)
*
time
.
Second
var
pingerCtx
context
.
Context
pingerCtx
,
stopPinger
=
context
.
WithCancel
(
c
.
Request
.
Context
())
// 退出时清理 pingerCtx 防止泄露
defer
stopPinger
()
pingerWg
.
Add
(
1
)
pingerWg
.
Add
(
1
)
gopool
.
Go
(
func
()
{
gopool
.
Go
(
func
()
{
defer
pingerWg
.
Done
()
defer
pingerWg
.
Done
()
...
@@ -166,9 +168,8 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
...
@@ -166,9 +168,8 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
}
}
resp
,
err
:=
client
.
Do
(
req
)
resp
,
err
:=
client
.
Do
(
req
)
// request结束后
停止ping
// request结束后
等待 ping goroutine 完成
if
info
.
IsStream
&&
pingEnabled
{
if
info
.
IsStream
&&
pingEnabled
{
stopPinger
()
pingerWg
.
Wait
()
pingerWg
.
Wait
()
}
}
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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