Skip to content

Rustdoc does not wait for DocFS writes to complete before exiting on Windows #109060

Closed

Description

@willcrichton

As discovered by @ehuss in rust-lang/cargo#10120, a Cargo test is intermittently failing on Windows because a source file generated by Rustdoc is not being written before the process exits. The suspected issue is that Rustdoc spawns asynchronous writes here:

rayon::spawn(move || {
fs::write(&path, contents).unwrap_or_else(|e| {
sender.send(format!("\"{}\": {}", path.display(), e)).unwrap_or_else(|_| {
panic!("failed to send error on \"{}\"", path.display())
})
});
});

However, Rustdoc never checks that the writes are completed. We should add a mechanism that prevents the process from exiting before these write tasks are completed.

One possible solution:

  • Add a field outstanding_writes: Arc<AtomicUsize> to DocFS.
  • Increment outstanding_writes at the start of DocFS::write, and decrement at the end of the spawned Rayon task.
  • Add a method DocFS::wait_for_outstanding_writes(&self) that spin-loops until outstanding_writes is zero. (Alternatively: use a condition variable, and have write notify the condvar when outstanding_writes is decremented.)
  • Either call wait_for_outstanding_writes explicitly in the end of the Rustdoc process, or add it as a Drop implementation to DocFS.

cc @GuillaumeGomez

Activity

  1. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    A-doctestsArea: Documentation tests, run by rustdoc
    on Mar 12, 2023
  2. removed
    A-doctestsArea: Documentation tests, run by rustdoc
    on Mar 13, 2023
  3. added 3 commits that reference this issue on Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions