Repository navigation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] 放宽到
OSError会把读失败当成「进程已消失」,让存活后代的断言静默通过ESRCH 这个诊断本身是对的:我在 WSL 上复现了同一条路径(
open('/proc/<pid>/stat')后 kill 该子进程再read()),三次读取均抛OSError/ProcessLookupError(errno 3),Path.read_text()同样如此。所以补ProcessLookupError是必要的。问题在捕获范围。
_process_exists()直接以_process_identity(pid) == identity作为「仍存活」判据,而本行现在把 EACCES、EMFILE、EIO、EBADF 一律变成return None,等价于「该 pid 不是记录中的进程」。后果是本文件第 938 行那条泄漏断言(assert time.monotonic() < deadline, "Detached descendants survived gate termination")与第 951 行assert not any(...)在读取失败时直接放行,而这两条恰恰是用来证明 gate 终止后没有残留后代的。仓库内同类读取的既有写法是窄口径:
src/powercontext/source_management/background.py:50:except (FileNotFoundError, ProcessLookupError): return Falsesrc/powercontext/source_management/durable.py:82:except (FileNotFoundError, ProcessLookupError): return True建议改为
except (FileNotFoundError, ProcessLookupError):,与生产侧保持一致;若确实想容忍其它OSError,请在return None前区分「进程不存在」与「读取失败」,后者应让断言失败而不是当作已消失。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed on 3948f2e with real Linux processes, without mocking
Path.read_text(): after recording a live child's start time, I loweredRLIMIT_NOFILEto 64 and exhausted the remaining descriptors.os.kill(pid, 0)still succeeded, but_process_exists(pid, identity)returnedFalse, so the cancellation test'sassert not any(...)passed for that live child. The parent commit instead raisedOSError(EMFILE); restoring descriptors made the same child detectable again.I also reproduced
ProcessLookupError(ESRCH)by opening/proc/<pid>/stat, terminating and reaping the child, then reading the open file. Please catch(FileNotFoundError, ProcessLookupError)so this race is handled without turning unrelated probe failures into evidence of successful cleanup.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: the narrow ESRCH fix is now on
mastervia #2396, in commit 9862ef4b._process_identity()already catches(FileNotFoundError, ProcessLookupError)there, handling the exit race while allowing unrelated read failures to surface.This PR is still at
3948f2eewith the broadOSErrorcatch and the previously demonstrated live-process false negative. Since the intended fix has already landed, I suggest closing this PR as superseded; retaining its broad catch when reconciling with master would weaken the assertion again.