From 5ada780f6ea45cb9613f972201947fc2614b843d Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Wed, 13 May 2026 02:00:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20stream=20channel=20=E6=8F=90=E5=89=8D?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=9C=AA=E5=85=B3=E9=97=AD=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=20goroutine=20=E6=B3=84=E6=BC=8F=EF=BC=8C=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=8E=A2=E6=B5=8B=E8=B6=85=E6=97=B6=E4=B8=8B=E9=99=90=20500ms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/port_scan.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/port_scan.go b/core/port_scan.go index edd0c34..bce2a86 100644 --- a/core/port_scan.go +++ b/core/port_scan.go @@ -127,6 +127,9 @@ func EnhancedPortScan(ctx context.Context, hosts []string, ports string, timeout hosts = probeSubnets(ctx, hosts, time.Duration(timeout)*time.Second, session) if len(hosts) == 0 { common.LogInfo(i18n.GetText("port_scan_no_alive_subnet")) + if stream != nil { + close(stream) + } return nil } } @@ -135,6 +138,9 @@ func EnhancedPortScan(ctx context.Context, hosts []string, ports string, timeout portList := parsers.ParsePort(ports) if len(portList) == 0 { common.LogError(i18n.Tr("invalid_port", ports)) + if stream != nil { + close(stream) + } return nil } common.LogDebug(fmt.Sprintf("[PortScan] 端口解析完成: %d个端口", len(portList))) @@ -203,6 +209,9 @@ func EnhancedPortScan(ctx context.Context, hosts []string, ports string, timeout }, state) if err != nil { common.LogError(i18n.Tr("thread_pool_create_failed", err)) + if stream != nil { + close(stream) + } return nil } common.LogDebug("[PortScan] 线程池创建成功") @@ -408,8 +417,13 @@ func scanSinglePort(ctx context.Context, host string, port int, addr string, ada // 步骤3:服务识别(Scanner负责关闭连接,包括探测中可能创建的新连接) scanner := NewSmartPortInfoScanner(ctx, host, port, conn, timeout, config, session) // 服务探测超时自适应:用 RTT 采样值约束读超时上限 + // 下限 500ms:服务处理需要时间,不能太激进 if rttTO := adaptiveTO.Timeout(); rttTO < timeout { - scanner.info.maxReadTimeoutMS = int(rttTO.Milliseconds()) * 6 + maxMS := int(rttTO.Milliseconds()) * 6 + if maxMS < 500 { + maxMS = 500 + } + scanner.info.maxReadTimeoutMS = maxMS } defer scanner.Close() serviceInfo, _ := scanner.SmartIdentify()