Skip to content
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

fix: disable multiplexing for some versions of curl #12234

Merged
merged 2 commits into from
Jun 7, 2023

Conversation

weihanglo
Copy link
Member

@weihanglo weihanglo commented Jun 6, 2023

What does this PR try to resolve?

Fixes #12202.
Zulip topic.

In certain versions of libcurl when proxy is in use with HTTP/2
multiplexing, connections will continue stacking up. This was
fixed in libcurl 8.0.0 in curl/curl@821f6e2

However, Cargo can still link against old system libcurl if it is from a
custom built one or on macOS. For those cases, multiplexing needs to be
disabled when those versions are detected.

How should we test and review this PR?

The first commit refactors how Cargo gets http.proxy config, so that
wecan have the detection inside Config. Please call it out if you
feel uncomfortable to this.

The second one did the trick, and a unit test is added.

Manual test the behavior

To manually test the behavior, you need to build cargo with
the all-static feature, which despite its name links libcurl
dynamically on macOS. It is a feature used by rustup distributions.

cargo b -F all-static

I don't really understand curl internals so had no luck to figure
out the relationship between proxies and HTTP/2 multiplexing.
I use hinata/nginx-forward-proxy to spin up a proxy to test curl's behavior.
It turns out that if there are fewer dependencies to download,
or we set MAX_CONCURRENT_STREAMS to a lower value in curl,
it largely affects the happening of the error no filter connected.

That implies multiplexing and http proxy are really influencing
each other in some way.

My patch to curl and curl-sys

diff --git a/Cargo.toml b/Cargo.toml
index ec9f878b3..3a687c309 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -205,3 +205,7 @@ vendored-libgit2 = ["libgit2-sys/vendored"]
 pretty-env-logger = ["pretty_env_logger"]
 # This is primarily used by rust-lang/rust distributing cargo the executable.
 all-static = ['vendored-openssl', 'curl/static-curl', 'curl/force-system-lib-on-osx']
+
+[patch.crates-io]
+curl = { git = "https://github.com/weihanglo/curl-rust", branch = "curlmopt" }
+curl-sys = { git = "https://github.com/weihanglo/curl-rust", branch = "curlmopt" }
diff --git a/src/cargo/sources/registry/http_remote.rs b/src/cargo/sources/registry/http_remote.rs
index 7e1f2a587..21ae3ca10 100644
--- a/src/cargo/sources/registry/http_remote.rs
+++ b/src/cargo/sources/registry/http_remote.rs
@@ -246,6 +246,8 @@ impl<'cfg> HttpRegistry<'cfg> {
                 .status("Updating", self.source_id.display_index())?;
         }
 
+        self.multi.set_max_concurrent_streams(10)?;
+
         Ok(())
     }

@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2023

r? @ehuss

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. A-configuration Area: cargo config files and env vars A-interacts-with-crates.io Area: interaction with registries A-networking Area: networking issues, curl, etc. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 6, 2023
@weihanglo
Copy link
Member Author

BTW. Although this is not really a regression, with sparse registry the number of connections is easier to exceed MAX_CONCURRENT_STREAMS (default to 100 in libcurl). Should we backport it at least for beta-nominated Nominated to backport to the beta branch. ?

Comment on lines 1723 to 1727
#[cfg(target_os = "macos")]
{
// We only take care of macOS now, since it is one of the major
// platforms. For other OS we encourage not to stick to older
// versions of libcurl.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little uncertain about making this macos only. What would be the concern with just checking this on all platforms?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was just me trying to shave off all old system libcurl aggressively 😅.

The constraint has been removed.

And weird. I forced pushed something but it didn't show up in this pull request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weihanglo weihanglo force-pushed the multiplexing branch 2 times, most recently from 644083d to 62bd959 Compare June 7, 2023 18:15
@ehuss
Copy link
Contributor

ehuss commented Jun 7, 2023

If you want to backport this to beta, that sounds good to me!

I think at some point it would be good to set up a proxy test using the container tests.

In certain versions of libcurl when proxy is in use with HTTP/2
multiplexing, connections will continue stacking up. This was
fixed in libcurl 8.0.0 in curl/curl@821f6e2

However, Cargo can still link against old system libcurl if it is from a
custom built one or on macOS. For those cases, multiplexing needs to be
disabled when those versions are detected.
@weihanglo
Copy link
Member Author

Thanks for the review!

@bors r=ehuss

I think at some point it would be good to set up a proxy test using the container tests.

Was thinking the same thing, though it feels a bit too hard to write one. I'll try when I have time. Thanks for the suggestion!

@bors
Copy link
Contributor

bors commented Jun 7, 2023

📌 Commit 6af8cb2 has been approved by ehuss

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 Jun 7, 2023
@bors
Copy link
Contributor

bors commented Jun 7, 2023

⌛ Testing commit 6af8cb2 with merge 41d662b...

@weihanglo weihanglo added the beta-nominated Nominated to backport to the beta branch. label Jun 7, 2023
@bors
Copy link
Contributor

bors commented Jun 7, 2023

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing 41d662b to master...

@bors bors merged commit 41d662b into rust-lang:master Jun 7, 2023
@weihanglo weihanglo deleted the multiplexing branch June 7, 2023 22:28
weihanglo pushed a commit to weihanglo/cargo that referenced this pull request Jun 7, 2023
fix: disable multiplexing on macOS for some versions of curl
@weihanglo weihanglo changed the title fix: disable multiplexing on macOS for some versions of curl fix: disable multiplexing for some versions of curl Jun 7, 2023
weihanglo pushed a commit to weihanglo/cargo that referenced this pull request Jun 7, 2023
fix: disable multiplexing for some versions of curl
bors added a commit that referenced this pull request Jun 8, 2023
[beta-1.70] backport #12234

Beta backports:

- #12234

In order to make CI pass, the following PRs are also cherry-picked:

- #12241
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 8, 2023
…nglo

[beta-1.71] cargo backport

1 commits in 64fb38c97ac4d3a327fc9032c862dd28c8833b17..cfd3bbd8fe4fd92074dfad04b7eb9a923646839f
2023-05-23 18:53:23 +0000 to 2023-06-08 08:44:47 +0000
- [beta-1.70] backport rust-lang/cargo#12234 (rust-lang/cargo#12242)

r? `@ghost`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 10, 2023
Update cargo

12 commits in b0fa79679e717cd077b7fc0fa4166f47107f1ba9..49b6d9e179a91cf7645142541c9563443f64bf2b
2023-06-03 14:19:48 +0000 to 2023-06-09 17:21:19 +0000
- docs: doc comments for all registry kinds (rust-lang/cargo#12247)
- chore: Migrate print-ban from test to clippy (rust-lang/cargo#12246)
- fix: fetch nested git submodules (rust-lang/cargo#12244)
- refactor: registry source cleanup (rust-lang/cargo#12240)
- test: loose overly matches for git cli output (rust-lang/cargo#12241)
- fix: disable multiplexing on macOS for some versions of curl (rust-lang/cargo#12234)
- docs: doc comments for registry source and index (rust-lang/cargo#12239)
- doc: point to nightly cargo doc (rust-lang/cargo#12237)
- Upgrade to `gix` v0.45 for multi-round pack negotiations. (rust-lang/cargo#12236)
- refactor: git source cleanup (rust-lang/cargo#12197)
- Add message on reusing previous temporary path on failed cargo installs (rust-lang/cargo#12231)
- doc: the first line should be a simple sentence instead of a heading (rust-lang/cargo#12228)

r? `@ghost`
@XVilka XVilka mentioned this pull request Jun 15, 2023
1 task
@ehuss ehuss added this to the 1.72.0 milestone Jun 22, 2023
Lctrs added a commit to Lctrs/composer that referenced this pull request Nov 22, 2024
I'm behind a corporate proxy and was hitting a `Curl 2 (...) [CONN-1-0] send: no filter connected` error when trying to download some packages.

Some google research led me to rust-lang/cargo#12202 and its fix rust-lang/cargo#12234.

This PR backports this fix to composer.

> In certain versions of libcurl when proxy is in use with HTTP/2
multiplexing, connections will continue stacking up. This was
fixed in libcurl 8.0.0 in curl/curl@821f6e2
Lctrs added a commit to Lctrs/composer that referenced this pull request Nov 22, 2024
I'm behind a corporate proxy and was hitting a `Curl 2 (...) [CONN-1-0] send: no filter connected` error when trying to download some packages.

Some google research led me to rust-lang/cargo#12202 and its fix rust-lang/cargo#12234.

This PR backports this fix to composer.

> In certain versions of libcurl when proxy is in use with HTTP/2
multiplexing, connections will continue stacking up. This was
fixed in libcurl 8.0.0 in curl/curl@821f6e2
Seldaek pushed a commit to composer/composer that referenced this pull request Nov 25, 2024
* disable multiplexing for some versions of curl

I'm behind a corporate proxy and was hitting a `Curl 2 (...) [CONN-1-0] send: no filter connected` error when trying to download some packages.

Some google research led me to rust-lang/cargo#12202 and its fix rust-lang/cargo#12234.

This PR backports this fix to composer.

> In certain versions of libcurl when proxy is in use with HTTP/2
multiplexing, connections will continue stacking up. This was
fixed in libcurl 8.0.0 in curl/curl@821f6e2

* fix has proxy condition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. A-configuration Area: cargo config files and env vars A-interacts-with-crates.io Area: interaction with registries A-networking Area: networking issues, curl, etc. beta-nominated Nominated to backport to the beta branch. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cargo download dependency failed "send: no filter connected"
4 participants