Skip to content

[rustdoc] Ensure that temporary doctest folder is correctly removed even if doctests failed #140706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 8, 2025

Conversation

GuillaumeGomez
Copy link
Member

Fixes #139899.

The bug was due to the fact that if any doctest fails for any reason, we call exit (or it's called inside libtest if not edition 2024), meaning that TempDir's destructor isn't called, and therefore the temporary folder isn't cleaned up.

Took me a while to figure out how to reproduce but finally I was able to reproduce the bug with:

#![doc(test(attr(deny(warnings))))]

//! ```
//! let a = 12;
//! ```

And then I ensured that panicking doctests were cleaned up as well:

//! ```
//! panic!();
//! ```

And finally I checked if it was fixed for merged doctests too (--edition 2024).

To make this work, I needed to add a new public function in libtest too which would call a function once all tests have been run.

So only issue is: I have absolutely no idea how we can add a regression test for this fix. If anyone has an idea...

r? @notriddle

…o allow a callback to be called before exiting
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 6, 2025
@GuillaumeGomez GuillaumeGomez force-pushed the fix-missing-temp-dir-cleanup branch from 9959875 to 173cdaf Compare May 6, 2025 17:32
@GuillaumeGomez
Copy link
Member Author

Applied suggestion.

@notriddle
Copy link
Contributor

Okay, so what would it take to build a run-make test of this? I understand if it's too much trouble, but I'd at least like to have some rationale, because without a regression test, this seems like it could easily regress.

@GuillaumeGomez
Copy link
Member Author

@lolbinarycat suggested a good way to test it so gonna write it.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label May 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 7, 2025

This PR modifies run-make tests.

cc @jieyouxu

@GuillaumeGomez
Copy link
Member Author

Added the regression test. Since tempfile is using std's tempdir and tempdir is using TMPDIR environment variable, we can decide where to put the temp output of rustdoc, so I did.

@jieyouxu
Copy link
Member

jieyouxu commented May 7, 2025

Added the regression test. Since tempfile is using std's tempdir and tempdir is using TMPDIR environment variable, we can decide where to put the temp output of rustdoc, so I did.

Just a caveat, on Windows the env vars are slightly different (TEMP, TMP, and another fallback), not that this really matters, since we go through std temp_dir() the same. I think this should also be reproducible on Windows and Apple hosts (as in this fix works), but you'd need to gate which env var is set.

@GuillaumeGomez
Copy link
Member Author

Hence why for now it's only run on linux. 😉

I can write a follow-up though to extend the tests to other platforms, but I'd like to get this merged as soon as possible for this bug to disappear.

@jieyouxu
Copy link
Member

jieyouxu commented May 7, 2025

Yeah, not blocking for sure 👍

@notriddle
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 7, 2025

📌 Commit 442ae63 has been approved by notriddle

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 7, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 7, 2025
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#140234 (Separate dataflow analysis and results)
 - rust-lang#140614 (Correct warning message in restricted visibility)
 - rust-lang#140671 (Parser: Recover error from named params while parse_path)
 - rust-lang#140700 (Don't crash on error codes passed to `--explain` which exceed our internal limit of 9999 )
 - rust-lang#140706 ([rustdoc] Ensure that temporary doctest folder is correctly removed even if doctests failed)
 - rust-lang#140734 (Fix regression from rust-lang#140393 for espidf / horizon / nuttx / vita)
 - rust-lang#140741 (add armv5te-unknown-linux-gnueabi target maintainer)
 - rust-lang#140745 (run-make-support: set rustc dylib path for cargo wrapper)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request May 7, 2025
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#140234 (Separate dataflow analysis and results)
 - rust-lang#140614 (Correct warning message in restricted visibility)
 - rust-lang#140671 (Parser: Recover error from named params while parse_path)
 - rust-lang#140700 (Don't crash on error codes passed to `--explain` which exceed our internal limit of 9999 )
 - rust-lang#140706 ([rustdoc] Ensure that temporary doctest folder is correctly removed even if doctests failed)
 - rust-lang#140734 (Fix regression from rust-lang#140393 for espidf / horizon / nuttx / vita)
 - rust-lang#140741 (add armv5te-unknown-linux-gnueabi target maintainer)
 - rust-lang#140745 (run-make-support: set rustc dylib path for cargo wrapper)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 83e3d0e into rust-lang:master May 8, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 8, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 8, 2025
Rollup merge of rust-lang#140706 - GuillaumeGomez:fix-missing-temp-dir-cleanup, r=notriddle

[rustdoc] Ensure that temporary doctest folder is correctly removed even if doctests failed

Fixes rust-lang#139899.

The bug was due to the fact that if any doctest fails for any reason, we call `exit` (or it's called inside `libtest` if not edition 2024), meaning that `TempDir`'s destructor isn't called, and therefore the temporary folder isn't cleaned up.

Took me a while to figure out how to reproduce but finally I was able to reproduce the bug with:

`````rust
#![doc(test(attr(deny(warnings))))]

//! ```
//! let a = 12;
//! ```
`````

And then I ensured that panicking doctests were cleaned up as well:

`````rust
//! ```
//! panic!();
//! ```
`````

And finally I checked if it was fixed for merged doctests too (`--edition 2024`).

To make this work, I needed to add a new public function in `libtest` too which would call a function once all tests have been run.

So only issue is: I have absolutely no idea how we can add a regression test for this fix. If anyone has an idea...

r? `@notriddle`
@GuillaumeGomez GuillaumeGomez added the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 8, 2025
@GuillaumeGomez GuillaumeGomez deleted the fix-missing-temp-dir-cleanup branch May 8, 2025 10:18
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 8, 2025
…oval, r=jieyouxu

Make `rustdoc-tempdir-removal` run-make tests work on other platforms than linux

Follow-up of rust-lang#140706.

r? `@jieyouxu`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 8, 2025
…oval, r=jieyouxu

Make `rustdoc-tempdir-removal` run-make tests work on other platforms than linux

Follow-up of rust-lang#140706.

r? ``@jieyouxu``
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2025
Rollup merge of rust-lang#140800 - GuillaumeGomez:rustdoc-tempdir-removal, r=jieyouxu

Make `rustdoc-tempdir-removal` run-make tests work on other platforms than linux

Follow-up of rust-lang#140706.

r? `@jieyouxu`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs beta-nominated Nominated for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thousands of /tmp/rustdoctest* directories
5 participants