Repository navigation
Conversation
|
I started with Would you prefer to keep this PR focused on |
| - uses: Swatinem/rust-cache@v2 | ||
| - uses: taiki-e/install-action@nextest | ||
| - uses: taiki-e/install-action@just | ||
| - name: Install syscall fault-injection test dependency |
There was a problem hiding this comment.
strace lets the tests force ENOMEM during ring setup and buffer registration
without exhausting memory on the CI runner.
| } | ||
| } | ||
|
|
||
| fn minimum_descriptor_limit(occupied: &[u32], additional: u128) -> Result<u128, Error> { |
There was a problem hiding this comment.
Existing descriptors can remain open above a lowered soft limit. Counting every open descriptor would therefore give the wrong number of available slots. This walks the descriptor numbers and also accounts for occupied slots between the current limit and the higher limit suggested in the error message.
| impl<Q: SubmissionQueue> Io<Q> { | ||
| pub fn new(sq: BackloggedSubmissionQueue<Q>, config: &Config) -> Self { | ||
| Self { | ||
| pub fn new(sq: BackloggedSubmissionQueue<Q>, config: &Config) -> io::Result<Self> { |
There was a problem hiding this comment.
Io::new now returns read-buffer initialization errors instead of panicking. The added unwrap calls are in tests constructing valid fixtures; the production caller propagates the error with ?.
Also keep the compatibility note in the PR description: existing TOML files work through defaults, but exhaustive Rust Config initializers need the new fields.
|
Thank you for you contribution and clarifying comments! Really nice to add the fault injection via strace :) Overall it looks good but I would prefer to split this up to smaller pieces if that's alright. Makes it a bit easier to review as well. I think one pr for the |
yes, make sense. both PRs under issue#151 or I create another issue specifically for |
|
Feel free to create a new issue! |
Check available descriptor slots at startup, allowing for the new ring, configured peer connections and 32 spare slots. Use a safe Rust snapshot of /proc/thread-self/fd, including sparse tables and descriptors above a lowered soft limit. Compute recovery limits against the occupied descriptor numbers and respect the hard limit. Keep limit reads in a checked libc helper. Preserve inspection errors, distinguish process EMFILE from system-wide ENFILE, and provide recovery guidance even when no descriptor remains for inspection. The snapshot does not reserve future capacity. RLIMIT_NOFILE protects sockets and files independently of the io_uring memory discussed in Nehliin#149. A limit of 64 cannot support the default 128 peers; this was reproduced as repeated Too many open files errors during peer discovery. Wait for the torrent worker startup result before starting DHT/UI and surface errors without panicking. Cover low and exhausted limits, sparse tables, higher inherited descriptors, hard/unlimited limits, syscall errors, concurrent descriptor changes, and CLI startup propagation. Use an invalid submission queue for the ring-setup regression so it does not depend on kernel MEMLOCK accounting. Queue a stop command to avoid hanging if setup unexpectedly succeeds, and assert that the original EINVAL reaches the caller. Implementation and tests were AI-assisted. Refs Nehliin#151.
Nehliin
left a comment
There was a problem hiding this comment.
Thanks, I think we can do some simplifications but I think the most important thing is that this doesn't become a fatal error. As mentioned in another comment I think we want to let this check create 1 new error variant and then WARN in the library if this is hit.
Ideally I think we have a warning "pop up" in the cli ui as well but not let this become a fatal error. You could also add an option to make it a hard error in the config but have it as a warning by default (that's up to you). However both the UI pop up and the config change can be done in a follow up pr instead if you want to limit the scope of this pr.
| Ok(required) | ||
| } | ||
|
|
||
| fn check_descriptor_budget( |
There was a problem hiding this comment.
Okay so I think this takes into account more edge cases than we realistically need.
- We do not need
u128we won't overflow u64 in any real scenariorlim_tis u64. Use saturating add instead and don't worry about the overflow. - The
minimum_descriptor_limitcatches an edge case I wasn't even aware of but since this is ran on startup I don't think we need the extra complexity of sort,dedup etc. It's fine to overestimate the number of open fds even if they won't count towards the soft limit.
| Ok(required) | ||
| } | ||
|
|
||
| fn check_descriptor_budget( |
There was a problem hiding this comment.
Okay so I think this takes into account more edge cases than we realistically need.
- We do not need
u128we won't overflow u64 in any real scenariorlim_tis u64. Use saturating add instead and don't worry about the overflow. - The
minimum_descriptor_limitcatches an edge case I wasn't even aware of but since this is ran on startup I don't think we need the extra complexity of sort,dedup etc. It's fine to overestimate the number of open fds even if they won't count towards the soft limit.
| )] | ||
| SystemFileDescriptorsExhausted(#[source] io::Error), | ||
| #[error("Could not read {resource}: {source}")] | ||
| LimitInspection { |
There was a problem hiding this comment.
I don't think we need this level of granularity in the errors, I'd prefer if we add a single new error variant for this feature (see my other comment)
| "Too many open files for this process: {source}\n\ | ||
| RLIMIT_NOFILE: soft {soft_limit}; hard {hard_limit}.\n{guidance}" | ||
| )] | ||
| FileDescriptorsExhausted { |
There was a problem hiding this comment.
You can keep this but rename it to FileDescriptorHeadRoomExhausted or something simillar
| } | ||
|
|
||
| #[test] | ||
| fn limit_read_failure_preserves_errno() { |
| @@ -1,69 +1,40 @@ | |||
| //! `Torrent::start` must report a failed io_uring setup to the caller rather | |||
There was a problem hiding this comment.
why change this test if you add another test?
| if limit.rlim_cur == libc::RLIM_INFINITY { | ||
| return Ok(()); | ||
| } | ||
| let entries = fs::read_dir("/proc/thread-self/fd") |
There was a problem hiding this comment.
If this fails due to chroot or SELinux or what not we should not crash the app
| result: &Receiver<color_eyre::Result<()>>, | ||
| ) -> color_eyre::Result<()> { | ||
| loop { | ||
| if matches!(events.peek(), Some(TorrentEvent::Running { .. })) { |
| } | ||
|
|
||
| #[test] | ||
| fn torrent_startup_result_reaches_the_cli() { |
There was a problem hiding this comment.
After reading this PR and think about the other MEMLOCK apporoach I think we want to switch the not-enough headroom from a hard error to a WARN instead in the log. OR we add config option like you did in the other pr to make it a fatal error but make this warn by default. We also don't take actual files needed into account here since we don't know how many files the resulting torrent will contain. So we will never be 100% sure the estimate is enough. It's at most a guidance for misconfiguration.
Closes #151.
Check descriptor capacity before startup, allowing for configured peers, the new ring, and 32 spare slots. Handle sparse descriptor tables and report actionable errors before opening the TUI.
Testing with NOFILE=64 reproduced failures with the default 128-peer configuration. MEMLOCK work is tracked separately in #175.
Verified: 193 tests passed, plus formatting, clippy, and CLI checks. The Transmission-backed test was skipped because its container was unavailable.
Implementation and tests were AI-assisted.