Repository navigation
fix: avoid index.lock contention when polling repository status - #37
Merged
Merged
Conversation
getStatus currently runs plain 'git status --porcelain', which refreshes stale stat information by rewriting .git/index. Assert that the index is left untouched so the monitoring path cannot compete for index.lock.
Run status with --no-optional-locks so the 30s monitor never rewrites .git/index, and await the optional fetch instead of detaching it into an unawaited Task so a slow fetch cannot overlap the next refresh cycle.
|
PR本文に |
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.
概要
30秒ごとの監視で走る
git statusが、ユーザー自身の git 操作をfatal: Unable to create '.../.git/index.lock': File existsで失敗させることがある。git statusはワーキングツリー走査で古くなった stat 情報を見つけると、index を書き戻すために
.git/index.lockを取る(読み取り専用に見えて実際は書く)。監視対象4リポジトリ × 30秒間隔でこれが走るため、ユーザーが
git checkoutやgit commitした瞬間にロックが衝突する。再現
400ファイルのリポジトリで、
git status5並列にgit checkoutをぶつけた結果:git status --porcelain(現行)git --no-optional-locks status --porcelain--no-optional-locksは「index 更新は任意」と git に伝えるフラグで、まさにこの用途(監視ツールが index を書かないようにする)のために用意されている。
なお
git status側は index リフレッシュを best-effort 扱いにしており、ロックが取れなくても黙って握り潰して exit 0 で終わる。つまり被害を受けるのは
常にユーザー側の git コマンドで、GitPeek 側のログには何も残らない。
変更内容
getStatusをgit --no-optional-locks status --porcelainに変更。監視ループが
.git/indexを書き換えなくなるupdateRepositoryの fetch を detach されたTask {}からawaitに変更。誰も待たないため前サイクルの fetch が次サイクルと重なり得た
branch --show-current/rev-parse/remote get-url/worktree listはindex を書かないことを確認済みのため、そのまま。
テスト
testGetStatus_doesNotRewriteIndexを追加。stat 情報を意図的に古くしてからgetStatusを呼び、.git/indexの mtime が変わらないことを検証する(修正前は fail、修正後は pass を確認)
ViewSnapshotTestsの4件は main でも同様に失敗する既存の失敗で、本 PR とは無関係