Repository navigation
fix: end a tied ssh's whole process tree, orphans included, before its attempt ends - #1847
Merged
Merged
Conversation
…s as ended On Linux the tied supervisor is a child subreaper, so a process whose parent ends comes back under it; when the child exits the supervisor kills what is under it until nothing lives, and the owner's kill stops the supervisor and does the same before ending it. On macOS the tree is what chains by parent unique id to the supervisor or the child, whose ids the owner reads while the child is held before it runs. The sampling keeper is gone.
…d an exiting process as alive The watcher no longer stops the supervisor after the owner's death: a stopped member of a group with no parent outside it gets the whole group hung up, which ended the walk before it reached the orphan. It sends TERM instead, and the supervisor ends what is under it. On Linux a process whose first thread ended still lists Z while its other threads exit, so is_alive now waits for the last thread; on both systems a process reaped between signal 0 and the state read counts as ended. The orphan tests wait until the orphan has left the group, so the group's kill cannot end it for them.
A tied child's supervisor is now this program started again, which a constructor runs before main: one end, identity-checked and judged by is_alive alone, runs when the child exits, when the owner says end and when the owner dies, and an end past its bound is an error rather than a status. Windows confirms the job runs nothing before a tied child counts as ended.
…ed end A look that finds nothing no longer counts as the tree's end. On Linux the end waits for the kernel to say the supervisor has no child left (ECHILD), reaping as it looks and keeping the child's status, so a process started after the /proc pass, or one that cannot be pinned, keeps the end open. On macOS a look proves the end only when it read the whole table and every existing process's ids, and the ids found are kept from look to look; a failed read of the supervisor's or child's own ids ends the start before the child runs. A start is rolled back only while the supervisor still holds the child. Once it said `spawned`, silence or its end hands the child to its owner, whose end of it runs the tree's end; after `failed` it says `confirmed 0`. The supervisor ignores HUP, INT, QUIT, TERM and PIPE from before it starts the child, which gets them back as they were given. Its diagnostic write gives up after a second and its watch writes never block, and a tied child's drop waits for its supervisor within a bound, kills it, and leaves one that still runs to a reaping thread. The supervisor state is boxed, so every owner of a child stays small (clippy large_enum_variant). `program_replaced` names the macOS error for a program file an update replaced.
…gram On macOS a hided left running from a bundle an update replaced cannot start ssh. The device row now says Hide was updated and to quit and open it again, which starts the new build, instead of an error about the tied supervisor.
…its drop The supervisor now says spawned while it still holds the child and lets it go only once the owner answers go inside its start bound; an owner that gave up never answers, so the supervisor ends the held child itself (marker v2). macOS proves an end only by two quiet looks in a row, and a member that ends between the process table and the look makes that look not quiet. Every tied diagnostic goes through a nonblocking description of its own and is dropped when it does not fit, and children a drop could not reap go to one capped reaper thread per process instead of a thread each.
… Retry A program_replaced failure is now the typed problem hide_updated, whose action is reopen_hide. The device row, a node's stopped core link strip and the move dialog's connection check say in four languages that Hide was updated and must be opened again, and none offers Retry or dials on its own.
# Conflicts: # docs/ARCHITECTURE.md
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.
Closes with-hide/hide-private#335
Closes with-hide/hide-private#337
Related: #1843, #1830
Summary
ssh가 띄운 프로세스가setsid로 떨어져 나가고 부모가 바로 끝나면, 그 프로세스가ssh보다 오래 살아남을 수 있었습니다(Windows 기기 브리지: 원격 데몬의 pane bootstrap을 LocalListener/LocalStream 위로 #335).지금까지는 표본을 떠서 기억해 둔 프로세스만 정리했기 때문입니다.
ssh를 감독하는 프로세스는 셸이 아니라 Hide 자신의 프로그램입니다.같은 프로그램을 감독 역할로 한 번 더 띄우고,
main보다 먼저 감독 일을 시작합니다.ssh가 끝날 때, 취소할 때, Hide가 갑자기 죽을 때 모두 그 하나를 씁니다.Linux는 커널이 "남은 자식이 없다"고 답할 때만 끝난 것으로 칩니다.
macOS는 프로세스 표를 빠짐없이 읽고 하나도 못 찾은 look이 두 번 연달아 나올 때만 끝난 것으로 칩니다.
표를 읽고 거르는 사이에 사라진 프로세스가 있었다면 그 look은 세지 않습니다.
ssh는 Hide가 "시작해도 된다"(go)고 답한 뒤에만 돌기 시작합니다.시작을 기다리다 포기한 Hide는 답하지 않으므로, 감독이 붙잡고 있던
ssh를 스스로 끝냅니다.그래서 Hide가 모르는
ssh가 남지 않습니다.감독과 Hide가 남기는 로그 한 줄은 막히지 않는 통로로만 쓰고, 못 쓰면 버립니다.
제때 거두지 못한 프로세스는 프로세스마다 하나인 스레드가 최대 64개까지 맡고, 넘치면 로그만 남깁니다.
ssh를 띄울 수 없습니다.이제 장비 줄, core 연결 띠, core 옮기기 점검이 "Hide를 종료하고 다시 열면 연결돼요"라고 네 언어로 말하고, 다시 시도 버튼을 내지 않습니다.
다시 시도해도 같은 이유로 실패하기 때문입니다.
Review
ctor크레이트의 생성자가main보다 먼저 돌며, 표시 변수가 없으면getenv한 번만 하고 바로 돌아갑니다)./proc/self/exe를 띄워서, 업데이트로 파일이 바뀌어도 지금 돌고 있는 그 파일을 씁니다.program_replaced오류로 답합니다.감독은
spawned를 말한 뒤 자식을 붙잡은 채go를 10초까지 기다립니다.Hide는 자기 시작 한도 안에서만
go를 씁니다. 그 뒤에는failed가 아닌 모든 결과(침묵, 감독의 끝)에서 자식을 호출자에게 넘기고, 그 끝은 다른 끝과 같은 정리를 거칩니다.ESRCH가 아닌 이유로 id를 못 읽은 프로세스가 하나라도 있으면 그 look은 증거가 되지 않습니다.
어떤 프로세스가 늘 그렇게 실패하면 모든 끝이 5초 뒤 "확인 안 됨"이 됩니다(이 Mac에서는 모든 프로세스가 답했습니다).
stderr가 일반 파일이면 그대로 쓰고, 아니면 이름으로 다시 열어 막히지 않는 통로를 따로 만듭니다(Linux는 소켓 말고 모두, macOS는 터미널만).
그 밖에는
/dev/null입니다.hide connect가 띄운 hided는 stderr가/dev/null이라 이 줄들은 거기서 사라집니다. 이번 변경 전부터 그랬고,hide-platform에서 hided의 로그로 가는 길은 없습니다.hide-platform/src/process.rs- ownership, failure path:started와 감독의start/answered:go를 주고받는 시작 약속.Tree::look_between: macOS에서 두 번 연달아 조용한 look.diagnostics_of_its_own,diagnose,Reaping/admit/reap_waiting,drop_tied.supervisor모듈은 생성자 안에서 돕니다. 그래서 C 라이브러리 호출과main준비가 필요 없는 표준 라이브러리만 씁니다.hide-node-link/src/device.rs,herdr-core/src/model.rs,contracts/snapshot-wire-enums.json- snapshot wire: 새 값hide_updated, 새 동작reopen_hide.web/src/settings.ts(retryCanHelp),web/src/connection.ts,web/src/settings/CoreMoveDialog.tsx: 다시 시도를 숨기는 세 곳.hide-node/src/ssh/host.rs: 끝이 확인되지 않으면host.child_end_unconfirmed를 남기고 시도를 놓지 않습니다.poll에서 잡니다./bin/sh대신 Hide 프로그램을 한 번 exec 하고, 시작 때 왕복 한 번(spawned/go)이 더 있습니다.Evidence
process.rs에 붙여 돌림):a_tied_supervisor_lets_its_child_go_only_once_its_owner_answers: 옛 감독은 버전 1이라 거절합니다. 버전 1 표시로 다시 돌리면, 답하지 않았는데도 자식을 돌렸습니다(failed 60대신started).unconfirmed_tied_drops_leave_no_thread_or_child_behind(stderr를 가득 채움): drop 6번에 스레드가 2개에서 8개로 늘었습니다.a_member_that_ends_between_the_table_and_the_look_leaves_no_proof(macOS 단위): 옛 코드에는look_between이 없어 붙일 수 없습니다. 규칙을 한 번의 look으로 되돌리면 실패합니다.hide_updated테스트들(core, web): 옛 코드에는 그 값이 없어 컴파일되지 않습니다.hide-platform,herdr-core,hide-node,hided,hide-node-link,hide-agent-hooks5118/5118.scripts/verify-cargo.sh lint, Windows 대상hide-platformclippy가 깨끗합니다.hide-node,hide-node-link,herdr-core,hided4418/4419입니다.실패 하나는 이 PR이 건드리지 않는
hided link_mux::tests::the_connection_ending_frees_every_stream입니다. 전체 병렬 실행 3번 중 2번 실패했고(한 번은 EINVAL, 한 번은 15초 대기), 혼자 20번 돌리면 모두 통과합니다.scripts/verify-web.sh: 2283 통과(1 건너뜀), desktop 298 통과(4 건너뜀).node scripts/check-design-contract.mjs통과.ubuntu:26.04이미지, 이 Mac의 Docker):process68/68, 단위 48/48, 끝난 뒤 남은 프로세스 없음. 워크스페이스cargo clippy --locked --workspace --all-targets -- -D warnings가 깨끗합니다.start()에서 감독이나 자식의 id 읽기가 실패하는 경로는 테스트가 없습니다.Verification record