charmcraft + Launchpad + Rust + Ubuntu lunar = weird download failures

Do you build your charms using Launchpad charm recipes? Are you building for Ubuntu 23.04 (lunar)? Do your charms have any Rust dependencies (directly or indirectly)? Do you see something like this in your build logs?

::             cargo build --manifest-path Cargo.toml --message-format=json-render-diagnostics --release -v --no-default-features --locked
::                 Updating index
::              Downloading crates ...
::             error: failed to download from ``
::             Caused by:
::               [2] Failed initialization ([CONN-1-0] send: no filter connected)

If all of the above conditions are true, then you don’t need to ask us to open a firewall hole to or anything like that, even though it looks very much as if you might need to do so. In fact, you’ve run into rust-lang/cargo#12202. Add this to the relevant part in your charm to work around the problem:


Thanks to Corey Bryant for this fascinating puzzle and for testing the workaround.