fix fish shell hang on startup#295
Open
sgnay wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: 修复连接 fish shell 时的启动卡顿问题 (主设备属性查询超时)
问题描述
本 PR 修复了当连接的远程主机默认 shell 为 fish 时,会出现的 10 秒卡顿和终端兼容性警告的问题。
表现症状
当建立 SSH 连接到运行 fish 的远程主机时,终端输出会挂起约 10
秒钟,之后才能显示命令提示符,并伴有以下警告:
warning: fish could not read response to Primary Device Attribute query after waiting for 10 seconds.
This is often due to a missing feature in your terminal. See 'help terminal-compatibility' or 'man
fish-terminal-compatibility'. This fish process will no longer wait for outstanding queries, which
disables some optional features.
根本原因
fish 启动时,会向 stdout 发送一个主设备属性 (Primary Device Attributes, DA1) 查询请求(转义序列 ESC [ c
或 ESC [ 0 c),以查询终端能力支持,并阻塞等待 stdin 上的响应。
由于 meatshell 的 SSH 工作线程原先没有拦截处理此查询并进行回复,该请求被直接忽略,导致远程 shell
保持阻塞,直到触发其内部 10 秒的读取超时。
解决方案
本 PR 在 SSH 连接的主力泵循环(src/ssh.rs)中,为该查询实现了自动拦截与响应机制。
// 响应主设备属性查询 (ESC [ c 或 ESC [ 0 c)
// 避免像 fish 这样的 shell 因等待响应而卡顿 10 秒。
let bytes = &data[..];
if bytes.windows(3).any(|w| w == b"\x1b[c")
|| bytes.windows(4).any(|w| w == b"\x1b[0c")
{
let _ = channel.data(&b"\x1b[?1;2c"[..]).await;
}
验证与影响
秒),命令提示符立刻显示且无任何警告信息。