Repository navigation
fix(convert): cap lsof's fd limit and bound the NBD release wait - #172
Merged
Merged
Conversation
lsof's startup cost grows with RLIMIT_NOFILE. A container that inherits a ~1e9 fd limit therefore spends minutes in every lsof call before it scans anything. The step 11 wait polls lsof up to 30 times, so a wait meant to last 30 seconds can stall for an hour, and it prints nothing while doing so. Add proc::lsof_capped, which lowers the soft fd limit to 1024 and adds a 10 second timeout for the lsof process only. The limit shortens lsof's own startup work without narrowing which files it can enumerate. Use the wrapper for the image probe and for the diagnostic lsof in the error trap. Bound the wait by wall-clock seconds instead of attempt count, print progress while a real holder keeps the image busy, and treat only lsof exit 0 or 1 as a definitive answer. A timeout or other probe failure is retried rather than read as "released", so the write-lock race the wait exists to prevent is not reintroduced. Assisted-by: Claude Code:deepseek-v4.1-flash-1017 [shellcheck] Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
|
@imlk0 ,您好,您的请求已接收,请耐心等待结果。 |
|
@imlk0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
cryptpilot-convertcan look like it hangs at step 11.disk::nbd_disconnect_and_waitpollslsof -t <image>to wait for qemu-nbd to release the write lock. lsof's startup cost grows withRLIMIT_NOFILE, so in a container that inherits a ~1e9 fd limit each call takes minutes before it scans anything. The 30-attempt loop turns a 30 second bound into an hour-long stall, and it prints nothing while waiting.Fix
proc::lsof_capped, which lowers the soft fd limit to 1024 and wraps the call intimeout 10for the lsof process only. The limit shortens lsof's own startup work without narrowing which files it can enumerate.Verification
bash -n,shellcheck cryptpilot-convert.sh,cargo fmt --check,make clippy,cargo build.nofile=16777216, a raw lsof takes about 2.7 s while the capped probe takes about 0.1 s; atnofile=1073741816, the capped probe takes about 0.1 s and still finds a holder on fd 3000. No-holder and self-fd-only cases return immediately; a holder is bounded by the wall clock; a failing probe is not read as released; progress prints at 0 s and 5 s.