mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-26 21:21:53 +08:00
fix: 修复凭据测试清理 goroutine 无限阻塞导致的 goroutine 泄漏
This commit is contained in:
@@ -77,13 +77,19 @@ func TestSingleCredential(ctx context.Context, cred Credential, authFn AuthFunc)
|
|||||||
case result := <-resultChan:
|
case result := <-resultChan:
|
||||||
return result
|
return result
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// context 被取消,但 goroutine 可能还在运行
|
// context 被取消,但 authFn goroutine 可能还阻塞在第三方库 IO 上
|
||||||
// 启动清理协程:等待结果并关闭连接
|
// 限时等待:超过 5 秒直接放弃,避免 goroutine 无限泄漏
|
||||||
go func() {
|
go func() {
|
||||||
result := <-resultChan
|
timer := time.NewTimer(5 * time.Second)
|
||||||
|
defer timer.Stop()
|
||||||
|
select {
|
||||||
|
case result := <-resultChan:
|
||||||
if result != nil && result.Conn != nil {
|
if result != nil && result.Conn != nil {
|
||||||
_ = result.Conn.Close()
|
_ = result.Conn.Close()
|
||||||
}
|
}
|
||||||
|
case <-timer.C:
|
||||||
|
// 第三方库不响应取消,放弃等待
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
return &AuthResult{
|
return &AuthResult{
|
||||||
Success: false,
|
Success: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user