Repository navigation
fix(remote): fs.readFile 不阻塞在命名管道上,只读取普通文件 (1lck/Lithe-IDEA#2270) - #164
Merged
Merged
Conversation
以 O_NONBLOCK | O_NOCTTY 打开后检查打开的句柄:目录仍是 IS_A_DIRECTORY, 套接字、命名管道和设备返回 UNSUPPORTED(与 fs.copy 顶层拒绝特殊文件同一个码), 不再让没有写端的命名管道一直占住工作线程,也消除 stat 与打开之间被换成特殊文件的竞态。
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.
关联 Issue
Fixes 1lck/Lithe-IDEA#2270。Refs 1lck/Lithe-IDEA#2231(远程开发完整设计)。
类型
fs.readFile读到命名管道时不再阻塞工作线程;不新增错误码,不新增日志事件改动说明
crates/remote/src/server/fs.rsread_file原来先File::open再检查类型。打开一个没有写端的命名管道时,open(2)会一直等到有进程打开写端,remote-worker线程就一直被占住;工作线程有上限,被占满后其他fs.*请求也会卡住。O_NONBLOCK | O_NOCTTY打开,然后检查打开的句柄的类型:IS_A_DIRECTORY。UNSUPPORTED。fs.copy在顶层遇到这些文件时用的也是这个码,含义相同(“这个操作不支持这种文件”),没有一码多义。O_NONBLOCK对普通文件的读取没有影响,所以不用再清掉它。fs.stat和fs.readFile之间路径被换成特殊文件时也能拒绝,不存在检查和读取之间的竞态。O_NOCTTY防止打开终端设备时,它成为远端服务进程的控制终端。contracts/remote-workspace-protocol-v1.mdfs.readFile行加上“只读取普通文件”。客户端影响
UNSUPPORTED在workspace里映射到process_failed,并带details.remoteCode。remote.readFile之前已经发了remote.stat、只打开普通文件,所以日常打开文件的行为不变。验证
cargo fmt -p lithe-remotecargo clippy -p lithe-remote --all-targets --all-features -- -D warnings:无警告cargo test -p lithe-remote --features server:全部通过,其中单元测试 159 个,新增两个:reading_a_fifo_without_a_writer_is_refused_without_blocking:用mkfifo建一个没有写端的命名管道,在另一个线程里读取,最多等 10 秒,结果必须是UNSUPPORTED。如果超时,测试会先打开写端放开被卡住的线程,再报失败,不会让测试进程挂住。reading_a_device_is_refused_and_a_regular_file_still_reads:/dev/zero返回UNSUPPORTED,目录返回IS_A_DIRECTORY,普通文件能完整读出并且eof为真。