@@ -290,6 +290,7 @@ func EnhancedPortScan(ctx context.Context, hosts []string, ports string, timeout
290290// slidingWindowSchedule 滑动窗口调度器
291291// ants.PoolWithFunc.Invoke 在池满时阻塞,天然提供反压,无需额外 semaphore
292292func slidingWindowSchedule (iter * SocketIterator , pool * AdaptivePool , wg * sync.WaitGroup ) {
293+ var dropped int64
293294 for {
294295 host , port , ok := iter .Next ()
295296 if ! ok {
@@ -304,11 +305,17 @@ func slidingWindowSchedule(iter *SocketIterator, pool *AdaptivePool, wg *sync.Wa
304305 }
305306 if err := pool .Invoke (task ); err != nil {
306307 wg .Done ()
308+ dropped ++
309+ common .LogError (i18n .Tr ("port_scan_task_dropped" , task .addr , err ))
307310 }
308311 }
309312
310313 // 等待所有任务完成
311314 wg .Wait ()
315+
316+ if dropped > 0 {
317+ common .LogError (i18n .Tr ("port_scan_tasks_dropped_total" , dropped ))
318+ }
312319}
313320
314321// fmtPort 无分配的端口号格式化
@@ -327,7 +334,10 @@ func fmtPort(port int) string {
327334 return string (buf [i :])
328335}
329336
330- // connectWithRetry 带重试的TCP连接 - 只对资源耗尽错误重试
337+ // connectWithRetry 带重试的TCP连接
338+ // - 资源耗尽错误:指数退避重试(maxRetries 次)
339+ // - 其他错误(如 connection refused、timeout):直接返回
340+ // timeout 是正常的扫描结果(防火墙 drop / filtered),不盲目重试
331341func connectWithRetry (ctx context.Context , session * common.ScanSession , addr string , timeout time.Duration , maxRetries int ) (net.Conn , error ) {
332342 var lastErr error
333343
@@ -340,9 +350,9 @@ func connectWithRetry(ctx context.Context, session *common.ScanSession, addr str
340350
341351 lastErr = err
342352
343- // 只对资源耗尽类错误重试,端口关闭直接返回
353+ // 只对资源耗尽类错误重试,端口关闭或超时直接返回
344354 if ! isResourceExhaustedError (err ) {
345- return nil , err
355+ return nil , lastErr
346356 }
347357
348358 // 记录资源耗尽错误
0 commit comments