2 Commits

Author SHA1 Message Date
xfy
f1dd8cbeb0 fix: complete Stage 1 deep review fixes
Batch 1 - Crash/data corruption:
- Add nil/empty config guards in server and app
- Protect against fasthttp buffer mutation in logging
- Ensure mimeutil falls back before caching empty MIME
- Make proxy health checker and resolver tolerate nil cfg
- Prevent Lua EMERG/ALERT/CRIT log levels from killing process

Batch 2 - Concurrency/race conditions:
- Add focused race tests for compression pool, ssl/ocsp,
  server proxies slice, Lua timer cancel, and TCP socket connect
- Fix Lua timer active race and socket ConnectAsync race

Batch 3 - Resource leaks/functional damage:
- Track and stop rate limiter cleanup goroutines on shutdown
- Add tests for proxy connection count leaks, server pool deadlock,
  Linux sendfile integrity, WebSocket frame data loss,
  stream UDP stop deadlock, and upstream name mismatch
- Fix stream ListenTCP/upstream lookup and UDP shutdown

Batch 4 - High severity technical debt:
- Add nil guard in security headers middleware
- Validate sliding window divisor and add tests
- Protect static handler fields with existing RWMutex
- Avoid mutating live HostClient.Addr on DNS updates
- Fix slow start Start/Stop and resolver restart
- Initialize variable fallback context maps
- Add tests for request_id/time_local and logging file handle close

Also:
- Relax integration variable performance threshold under race detector
- Update benchmark plan docs for new stream ListenTCP signature

Verification:
- make test: pass
- go test -race -count=1 ./internal/...: pass
- make lint: 0 issues
- make build: success
2026-06-17 09:48:43 +08:00
xfy
294ff73a7a test(variable): 添加变量系统覆盖测试(覆盖率 74.5% → 预计 >85%)
新建 internal/variable/builtin_coverage_test.go,覆盖低覆盖率函数:

formatRequestTime 测试(原 0%):
- 8 个子测试覆盖零值、毫秒、秒、大值等各种时间格式

SetGlobalVariables 测试(原 0%):
- 正常设置、空配置、覆盖、变量展开

EphemeralGet 测试(原 49.3%):
- 全局变量、回退、server_name、upstream_connect_time
- upstream_header_time、body_bytes_sent、request_time
- UserValue 响应信息、并发安全

GetSSLClientVerify 测试(原 40%):
- TLS UserValue 设置、对端证书存在、无效类型

init 注册验证测试(原 49.3%):
- 验证 16 个内置变量注册
- 验证 5 个 upstream 变量
- 验证 9 个 SSL 变量
- 验证 host/uri/request_uri/args/method 的 GetterBytes 注册
2026-06-04 08:21:48 +08:00