Skip to content

Cargo build hangs #88862

@Emilgardis

Description

@Emilgardis
Contributor

originally posted in zulip

Hi! I've found a regression in compilation introduced in #85499,

searched nightlies: from nightly-2021-08-17 to nightly-2021-09-10
regressed nightly: nightly-2021-08-26
searched commits: from b03ccac to 0afc208
regressed commit: 0afc208

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-pc-windows-msvc
Reproduce with:

# bisect-script.bat
pwsh.exe -noexit -Command "stop-job -Name cargobuild_bisect; if ((start-job -Name cargobuild_bisect { cargo build -p server 2>&1 } | wait-job -timeout 600).State -ne 'Completed') {receive-job -Name cargobuild_bisect; receive-job -Name cargobuild_bisect | remove-job -Force; exit 10} else {receive-job -Name cargobuild_bisect; receive-job -Name cargobuild_bisect | remove-job -Force; exit 0}"
cargo bisect-rustc --start=2021-08-17 --script .\bisect-script.bat

The issue is that compilation succeeds in a acceptable time before this change, but now it's seemingly taking forever, I have not tried this on linux, only windows so far. I'm not sure how I should report this because I'm not able to reproduce it outside my large workspace where I bisected this. Does anyone have an idea to what this could be or have a good way to figure out what the cause is?

some notable dependencies: actix-web, sqlx, serde, chrono, ring, tokio, tracing, reqwest,anyhow,eyre,async-trait and many more

I've tried

$ export CARGO_LOG="info"
$ export RUSTC_LOG="info" # to stop massive console spam I use this instead = "info,rustc_trait_selection=warn,rustc_codegen_ssa=warn,rustc_metadata=warn,rustc_mir=warn,rustc_query_system=warn,rustc_const_eval=warn"
$ cargo build -p server

which outputs at the end

┐rustc_query_system::dep_graph::serialized::encode_node node=NodeInfo { node: variances_of(7b5e03ed597c3c33-573328205f4d7f81), fingerprint: Fingerprint(12749739837320991735, 10040035723298659737), edges: [2870] }
┘
┐rustc_query_system::dep_graph::serialized::encode_node node=NodeInfo { node: variances_of(7b5e03ed597c3c33-6f459134164ff719), fingerprint: Fingerprint(8361987967435134197, 5478714612052799554), edges: [2870] }
┘
[2021-09-11T16:54:37Z INFO  cargo::core::compiler::job_queue] tokens in use: 0, rustc_tokens: [], waiting_rustcs: [] (events this tick: 0)
┐rustc_query_system::dep_graph::serialized::encode_node node=NodeInfo { node: variances_of(7b5e03ed597c3c33-82cb26faded76d4), fingerprint: Fingerprint(12749739837320991735, 10040035723298659737), edges: [2870] }
[2021-09-11T16:54:40Z INFO  cargo::core::compiler::job_queue] tokens in use: 0, rustc_tokens: [], waiting_rustcs: [] (events this tick: 1)
┘
[2021-09-11T16:54:40Z INFO  cargo::core::compiler::job_queue] tokens in use: 0, rustc_tokens: [], waiting_rustcs: [] (events this tick: 0)
┐rustc_query_system::dep_graph::serialized::encode_node node=NodeInfo { node: variances_of(7b5e03ed597c3c33-7c40a2b5f026df66), fingerprint: Fingerprint(12526569172406770563, 17126563881511896260), edges: [2870] }
[2021-09-11T16:54:40Z INFO  cargo::core::compiler::job_queue] tokens in use: 0, rustc_tokens: [], waiting_rustcs: [] (events this tick: 1)
┘
[2021-09-11T16:54:40Z INFO  cargo::core::compiler::job_queue] tokens in use: 0, rustc_tokens: [], waiting_rustcs: [] (events this tick: 0)
┐rustc_query_system::dep_graph::serialized::encode_node node=NodeInfo { node: variances_of(7b5e03ed597c3c33-c7d9e80976e93c5), fingerprint: Fingerprint(12526569172406770563, 17126563881511896260), edges: [2870] }
[2021-09-11T16:54:40Z INFO  cargo::core::compiler::job_queue] tokens in use: 0, rustc_tokens: [], waiting_rustcs: [] (events this tick: 1)
┘
[2021-09-11T16:54:40Z INFO  cargo::core::compiler::job_queue] tokens in use: 0, rustc_tokens: [], waiting_rustcs: [] (events this tick: 0)
    Building [=======================> ] 445/446: server(bin)

and then just hangs.

How do I proceed?

Activity

added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Sep 11, 2021
added
I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
and removed
regression-untriagedUntriaged performance or correctness regression.
on Sep 11, 2021
camelid

camelid commented on Sep 11, 2021

@camelid
Member
camelid

camelid commented on Sep 11, 2021

@camelid
Member

One way to minimize could be to see which crate in your workspace is triggering the hang. E.g., run cargo build -p my_crate for each of the crates in the workspace and find the one with the fewest dependencies (in-workspace dependencies, or external). Then you can try to minimize that crate further by deleting different parts of the code until the hang disappears.

Emilgardis

Emilgardis commented on Sep 12, 2021

@Emilgardis
ContributorAuthor

The crate/step which is failing is the final one. I managed to delete parts of the code to make the hang disappear but I'm not certain I've actually pinpointed it exactly yet.

I let it run and seems it failed on STATUS_STACK_BUFFER_OVERRUN
https://gist.github.com/Emilgardis/954c2aeefc0cca270a421a90ecc5067a#file-output-cargo-issue88862-log-L988

Emilgardis

Emilgardis commented on Sep 12, 2021

@Emilgardis
ContributorAuthor

ran with

[profile.dev]
lto = "off"
panic = "abort"
incremental = false

and the build completed after a while. The memory usage jumps up dramatically, from 138 MB to 7GB to 20GB, and then down again to repeat.

Same behaviour without those flags.

This is probably not a hang, just increased complexity causing longer run-time.

EDIT: On older nightly, the max memory usage is around 1.5GB

Emilgardis

Emilgardis commented on Sep 12, 2021

@Emilgardis
ContributorAuthor

Managed to minimize it somewhat. Was not able to remove all dependencies but most of them.

❯ cargo -Vv                                           
cargo 1.56.0-nightly (e96bdb0c3 2021-08-17)
release: 1.56.0
commit-hash: e96bdb0c3d0a418e7fcd7fbd69be08abf830b4bc
commit-date: 2021-08-17

takes 40-45 seconds to compile from clean state.


❯ cargo -Vv                                           
cargo 1.56.0-nightly (18751dd3f 2021-09-01)
release: 1.56.0
commit-hash: 18751dd3f238d94d384a7fe967abfac06cbfe0b9
commit-date: 2021-09-01

takes 125-500 seconds to compile from clean state. (and uses 5-7GB of memory sometimes)

I believe the issue is to do with the client traits and impls and tracing instrumentation. Replacing upsert_token with a todo!() makes compilation sane again.

https://gist.github.com/Emilgardis/194812fa2e73ff6839d9942163329887

camelid

camelid commented on Sep 12, 2021

@camelid
Member

@rustbot ping cleanup

I think it would be useful to further minimize the above Gist.

rustbot

rustbot commented on Sep 12, 2021

@rustbot
Collaborator

33 remaining items

added a commit that references this issue on Sep 27, 2021
2b6ed3b
Emilgardis

Emilgardis commented on Sep 27, 2021

@Emilgardis
ContributorAuthor

As a sanity check, I compiled with #89285 and it has fixed the issue in my workspace, thank you @jackh726 for looking into this!

jackh726

jackh726 commented on Sep 27, 2021

@jackh726
Member

It's a bit unfortunate I wasn't able to find a "real" fix, but as Niko said, a decent stopgap measure.

added a commit that references this issue on Oct 4, 2021
bb4672b
RalfJung

RalfJung commented on Aug 23, 2022

@RalfJung
Member

Looks like the stopgap measure is causing problems... at least if the analysis in rust-lang/miri#2433 is correct, the 'fix' is causing ICEs in Miri when rustc is built with debug assertions.

added a commit that references this issue on Sep 22, 2022
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.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-compilememIssue: Problems and improvements with respect to memory usage during compilation.I-compiletimeIssue: Problems and improvements with respect to compile times.ICEBreaker-Cleanup-CrewHelping to "clean up" bugs with minimal examples and bisectionsP-mediumMedium priorityregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @RalfJung@Emilgardis@hkratz@steffahn@smmalis37

      Issue actions

        Cargo build hangs · Issue #88862 · rust-lang/rust