Skip to content

Commit 84dfbf8

Browse files
author
zhangtao
committed
fix: 修复 SSH 非阻塞终端读取立即关闭
1 parent b777966 commit 84dfbf8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎backend/app/modules/ops/ssh/terminal.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ def _reader(sess: TerminalSession) -> None:
121121
while not sess.closed:
122122
try:
123123
data = sess.channel.recv(_READ_CHUNK)
124-
except Exception: # noqa: BLE001 - 通道关闭/超时都视为结束
124+
except (TimeoutError, BlockingIOError):
125+
# 通道为 setblocking(False):无数据时抛超时/阻塞异常,不能当作 EOF
126+
time.sleep(_POLL_INTERVAL)
127+
continue
128+
except Exception: # noqa: BLE001 - 通道关闭视为结束
125129
break
126130
if not data:
127131
break

0 commit comments

Comments
 (0)