修复就绪屏障位被消费致FTP永不监听;新增栈可观测(水位探针+静态调用图报告)并补FTP实测
This commit is contained in:
+41
-13
@@ -37,6 +37,33 @@ def send_cmd(sock, cmd):
|
||||
time.sleep(0.1)
|
||||
return recv_line(sock)
|
||||
|
||||
def connect_with_retry(host, port, timeout=15.0, attempts=6, delay=3.0):
|
||||
"""连接控制通道(带重试)。
|
||||
|
||||
CH395F 单客户端复用:上一会话未 QUIT 就断开时,服务端可能仍在处理旧连接,
|
||||
新连接会被 RST(WinError 10061);实测约 30s 后服务端丢弃旧会话并重新 listen。
|
||||
注意不要用裸 TCP 探测端口(探测会占掉唯一会话)。
|
||||
"""
|
||||
last_err = None
|
||||
for i in range(1, attempts + 1):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(timeout)
|
||||
try:
|
||||
s.connect((host, port))
|
||||
return s, None
|
||||
except Exception as e:
|
||||
last_err = e
|
||||
try:
|
||||
s.close()
|
||||
except Exception:
|
||||
pass
|
||||
if i < attempts:
|
||||
print(f" connect failed ({e}); retry {i}/{attempts - 1} in {delay:.0f}s "
|
||||
f"(single-client: stale session blocks new connections)")
|
||||
time.sleep(delay)
|
||||
return None, last_err
|
||||
|
||||
|
||||
def parse_pasv(resp):
|
||||
m = re.search(r"(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)", resp.decode())
|
||||
if m:
|
||||
@@ -80,22 +107,23 @@ def test_speed(host, port, size_kb):
|
||||
|
||||
# ---- Connect + Login ----
|
||||
print("[Connect] Connecting...")
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(60.0)
|
||||
try:
|
||||
sock.connect((host, port))
|
||||
except Exception as e:
|
||||
print(f" CONNECT FAILED: {e}")
|
||||
check("Connect", False, str(e))
|
||||
return finish(sock)
|
||||
sock, err = connect_with_retry(host, port, timeout=60.0)
|
||||
if sock is None:
|
||||
print(f" CONNECT FAILED: {err}")
|
||||
check("Connect", False, str(err))
|
||||
return finish(None)
|
||||
recv_line(sock) # 220
|
||||
if not send_cmd(sock, "USER anonymous"):
|
||||
check("Login USER", False)
|
||||
resp = send_cmd(sock, "USER anonymous")
|
||||
if not (resp and resp.startswith(b"230")):
|
||||
check("Login USER 230", False,
|
||||
resp.decode(errors='replace').rstrip() if resp else "no resp")
|
||||
return finish(sock)
|
||||
if not send_cmd(sock, "PASS test@test.com"):
|
||||
check("Login PASS", False)
|
||||
resp = send_cmd(sock, "PASS test@test.com")
|
||||
if not (resp and resp.startswith(b"230")):
|
||||
check("Login PASS 230", False,
|
||||
resp.decode(errors='replace').rstrip() if resp else "no resp")
|
||||
return finish(sock)
|
||||
check("Login (USER/PASS)", True)
|
||||
check("Login (USER/PASS 230)", True)
|
||||
send_cmd(sock, "TYPE I")
|
||||
|
||||
# ---- Upload ----
|
||||
|
||||
Reference in New Issue
Block a user