Skip to content

test: let the device writer take its lock while a test waits for its lines - #1828

Merged
yansfil merged 1 commit into
mainfrom
fix/device-writer-starvation
Oct 29, 2026
Merged

yansfil merged 1 commit into
mainfrom
fix/device-writer-starvation

Conversation

@yansfil

@yansfil yansfil commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes with-hide/hide-private#164
Closes with-hide/hide-private#143

Summary

Linux CI에서 a_pane_past_its_unsent_keys_reads_ended_while_other_panes_keys_go_on가 5 s 대기 끝에 실패하던 원인을 고칩니다.
테스트의 기다림이 잠금을 쥔 채 링크가 받은 줄 전부(16 KiB 키 줄 17개)를 매번 다시 파싱했고, writer는 줄마다 같은 잠금이 필요해 그 잠금을 얻지 못하고 굶었습니다.
이제 기다림은 링크가 줄을 받을 때까지 잠들고, 새 줄만 잠금 안에서 복사해 밖에서 한 번씩 파싱하며, 조건은 마지막 줄만 봅니다.
같은 파일의 link 대기 9곳을 이 기다림으로 바꿨습니다. 제품 코드와 대기 시간(WAIT)은 바뀌지 않습니다.
#1817(읽기를 cap overflow 전에 시작한 순서 문제)과는 다른 원인입니다.

Review

  • 판단해 주세요: 링크 대기의 조건을 "마지막 줄이 기다리는 key 줄"로 바꿨습니다. 각 테스트에서 그 줄이 큐의 마지막이라 그 뒤 줄이 오면 실패합니다.
  • 조심해서 볼 파일: hide-node/src/terminal/device_tests.rs - GatedLink::wait_for_lines가 written 잠금과 새 wrote Condvar를 씁니다.
  • 조심해서 볼 파일: 같은 파일 64-pane 테스트 - 예전 대기는 p63에서 멈추고 그 뒤에 큐된 p0 Enter를 다시 읽기로 셌습니다. 이제 마지막에 큐된 p1 Enter를 기다립니다.

Evidence

  • 확인한 것: 원인. 고치기 전 이 Mac에서 24개 병렬로 잰 결과, release 뒤 writer가 written 잠금을 기다린 시간이 대기 전체와 거의 같았습니다(예: 대기 53 ms 중 테스트가 쥔 시간 44 ms, writer가 기다린 시간 43 ms).
  • 확인한 것: 고친 뒤 같은 측정에서 writer의 잠금 대기는 실행당 약 1 µs(최대 0.99 ms)입니다.
  • 확인한 것: 대상 테스트를 최종 빌드로 48개 병렬 x 40회(CPU burner 14개, load 최대 167): 1920회 중 0회 실패.
  • 확인한 것: device 모듈 24개 테스트 전체를 load 70-95에서 480회 반복: 0회 실패.
  • 확인한 것: 64-pane 테스트는 load 130-167에서 고치기 전 176회 중 151회, 고친 뒤 600회 중 23회 실패했습니다. 남은 실패는 debug 빌드로 16 MiB 키를 인코딩하는 writer의 실제 일이 그 load에서 5 s 가드에 닿은 것입니다.
  • 확인한 것: verify-cargo.sh fmt-check, clippy -p hide-node --all-targets -D warnings, nextest -p hide-node(224 통과).
  • 확인하지 못한 것: 대상 테스트는 이 Mac에서 고치기 전에도 2520회(load 최대 38) 중 0회 실패해, 실패 자체는 로컬에서 재현하지 못했습니다(실패는 Linux 전용). 증거는 위 잠금 대기 측정과 코드이고, Linux 확인은 PR CI에 맡깁니다.
  • 확인하지 못한 것: Windows, Linux 로컬 반복(이 기계에 없음).
Verification record
  • base 4a856f5, head b9d8c86
  • 재현 명령: target/debug/deps/hide_node-* --exact terminal::device::tests::a_pane_past_its_unsent_keys_reads_ended_while_other_panes_keys_go_on 병렬 반복

…lines

A test waiting for the gated link's lines polled by parsing every line
under the lock the writer takes for each line it writes, so on Linux the
writer could not get the lock past the wait. The wait now sleeps until
the link takes a line, copies only the new lines under the lock and parses
each once, and its condition reads only the last line.

Closes with-hide/hide-private#164
Closes with-hide/hide-private#143
@yansfil
yansfil merged commit 411589e into main Oct 29, 2026
48 checks passed
@yansfil
yansfil deleted the fix/device-writer-starvation branch October 29, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant