优化自适应扫描系统 & 修复 POC 调度问题

自适应扫描优化:
- target/ceiling 分离,自适应池可向上探索而非锁死在 target
- assessHealth 阈值按网络环境区分(LAN 收紧 / Internet 放宽)
- RTT 漂移时动态压低 target,配合 AIMD 双重降速
- 去掉 semaphore 双层流控,由 ants pool 统一反压
- 探测端口从 3 个扩充到 8 个,减少 RTT 采样偏差
- computeRetries 按环境调整目标概率和上限

Bug 修复:
- AdaptivePool.Wait() 加 10 分钟超时,防止 goroutine 卡死时永久挂起
- CEL 环境初始化失败后允许重试(sync.Once → sync.Mutex + 标志位)
- CAS 自旋加 runtime.Gosched() 退避,减少高并发下 CPU 空转
- -full 模式下 web 插件跳过 IsMarkedWebService 检查 #588
- 不确定服务补做 HTTP 回退探测,覆盖自定义框架漏网场景
- POC sets 纯字面量值跳过 CEL 编译,消除大量误报错误日志
This commit is contained in:
ZacharyZcR
2026-06-14 22:23:48 +08:00
committed by ZacharyZcR
parent c49c23c7f0
commit 8402be98e3
15 changed files with 798 additions and 104 deletions
+41 -38
View File
@@ -28,7 +28,8 @@ import (
// 基础CEL环境缓存(避免重复创建,减少内存分配)
var (
baseEnvOnce sync.Once
baseEnvMu sync.Mutex
baseEnvInited bool
baseEnv *cel.Env
baseProgramOpt []cel.ProgramOption
)
@@ -52,47 +53,49 @@ func NewEnv(c *CustomLib) (*cel.Env, error) {
return cachedCELEnv, cachedCELEnvErr
}
// initBaseEnv 初始化基础CEL环境(只执行一次)
// initBaseEnv 初始化基础CEL环境(失败后允许重试)
func initBaseEnv() {
baseEnvOnce.Do(func() {
// 收集所有函数声明
var allDeclarations []*exprpb.Decl
allDeclarations = append(allDeclarations, registerStringDeclarations()...)
allDeclarations = append(allDeclarations, registerEncodingDeclarations()...)
allDeclarations = append(allDeclarations, registerCryptoDeclarations()...)
allDeclarations = append(allDeclarations, registerRandomDeclarations()...)
allDeclarations = append(allDeclarations, registerMiscDeclarations()...)
baseEnvMu.Lock()
defer baseEnvMu.Unlock()
if baseEnvInited {
return
}
// 收集所有函数实现
var allImplementations []*functions.Overload
allImplementations = append(allImplementations, registerStringImplementations()...)
allImplementations = append(allImplementations, registerEncodingImplementations()...)
allImplementations = append(allImplementations, registerCryptoImplementations()...)
allImplementations = append(allImplementations, registerRandomImplementations()...)
allImplementations = append(allImplementations, registerMiscImplementations()...)
var allDeclarations []*exprpb.Decl
allDeclarations = append(allDeclarations, registerStringDeclarations()...)
allDeclarations = append(allDeclarations, registerEncodingDeclarations()...)
allDeclarations = append(allDeclarations, registerCryptoDeclarations()...)
allDeclarations = append(allDeclarations, registerRandomDeclarations()...)
allDeclarations = append(allDeclarations, registerMiscDeclarations()...)
// 保存程序选项供后续使用
//nolint:staticcheck // SA1019: cel.Functions已废弃但CEL库尚未提供替代方案
baseProgramOpt = []cel.ProgramOption{cel.Functions(allImplementations...)}
var allImplementations []*functions.Overload
allImplementations = append(allImplementations, registerStringImplementations()...)
allImplementations = append(allImplementations, registerEncodingImplementations()...)
allImplementations = append(allImplementations, registerCryptoImplementations()...)
allImplementations = append(allImplementations, registerRandomImplementations()...)
allImplementations = append(allImplementations, registerMiscImplementations()...)
// 创建基础环境
var err error
baseEnv, err = cel.NewEnv(
cel.Container("lib"),
cel.Types(&UrlType{}, &Request{}, &Response{}, &Reverse{}),
//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案
cel.Declarations(
decls.NewIdent("request", decls.NewObjectType("lib.Request"), nil),
decls.NewIdent("response", decls.NewObjectType("lib.Response"), nil),
decls.NewIdent("reverse", decls.NewObjectType("lib.Reverse"), nil),
),
//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案
cel.Declarations(allDeclarations...),
)
if err != nil {
common.LogError(i18n.Tr("webscan_cel_init_failed", err))
}
})
//nolint:staticcheck // SA1019: cel.Functions已废弃但CEL库尚未提供替代方案
baseProgramOpt = []cel.ProgramOption{cel.Functions(allImplementations...)}
var err error
baseEnv, err = cel.NewEnv(
cel.Container("lib"),
cel.Types(&UrlType{}, &Request{}, &Response{}, &Reverse{}),
//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案
cel.Declarations(
decls.NewIdent("request", decls.NewObjectType("lib.Request"), nil),
decls.NewIdent("response", decls.NewObjectType("lib.Response"), nil),
decls.NewIdent("reverse", decls.NewObjectType("lib.Reverse"), nil),
),
//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案
cel.Declarations(allDeclarations...),
)
if err != nil {
common.LogError(i18n.Tr("webscan_cel_init_failed", err))
return
}
baseEnvInited = true
}
// GetBaseEnv 获取基础CEL环境