Skip to content

http: add a config to limit the connection time#2362

Open
GalaxySnail wants to merge 1 commit into
git:masterfrom
GalaxySnail:http-connect-timeout-ms
Open

http: add a config to limit the connection time#2362
GalaxySnail wants to merge 1 commit into
git:masterfrom
GalaxySnail:http-connect-timeout-ms

Conversation

@GalaxySnail

Copy link
Copy Markdown

No description provided.

@gitgitgadget-git

Copy link
Copy Markdown

Welcome to GitGitGadget

Hi @GalaxySnail, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that either:

  • Your Pull Request has a good description, if it consists of multiple commits, as it will be used as cover letter.
  • Your Pull Request description is empty, if it consists of a single commit, as the commit message should be descriptive enough by itself.

You can CC potential reviewers by adding a footer to the PR description with the following syntax:

CC: Revi Ewer <revi.ewer@example.com>, Ill Takalook <ill.takalook@example.net>

NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description,
because it will result in a malformed CC list on the mailing list. See
example.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "revisions:" to state which subsystem the change is about, and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the Libera Chat IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this. Note that any reviewers CC'd via the list in the PR description will not actually be sent emails.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail).

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the (raw) link), then import it into your mail program. If you use GMail, you can do this via:

curl -g --user "<EMailAddress>:<Password>" \
    --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

Need help?

New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Libera Chat. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

@dscho

dscho commented Jul 22, 2026

Copy link
Copy Markdown
Member

/allow

@gitgitgadget-git

Copy link
Copy Markdown

User GalaxySnail is now allowed to use GitGitGadget.

@GalaxySnail

Copy link
Copy Markdown
Author

/preview

@gitgitgadget-git

Copy link
Copy Markdown

Error: Could not determine full name of GalaxySnail

@GalaxySnail

Copy link
Copy Markdown
Author

Error: Could not determine full name of GalaxySnail

What's happening?

@dscho

dscho commented Jul 23, 2026

Copy link
Copy Markdown
Member

Error: Could not determine full name of GalaxySnail

What's happening?

@GalaxySnail The Git project requires "Random J Developer random@developer.example.org"-like sign-offs, and GitGitGadget enforces that even for your own Cc: to which your email gets sent (so that the conversation on the Git mailing list about your patch includes you).

To determine your name and email, GitGitGadget looks at your public GitHub info. The user name is obtained via GitHub's REST API, and if you look at the response of https://api.github.com/users/GalaxySnail you will notice that both name and email are null. GitGitGadget can therefore not send anything with you in Cc: and refuses to send anything at all.

@GalaxySnail

GalaxySnail commented Jul 23, 2026

Copy link
Copy Markdown
Author

Thanks! I have set my name in the user profile now. However, although I have already set my public email to me@glxys.nl, the email field in this api is still null. I also checked that the "keep my email addresses private" setting is "off". That's weird.

edit: It seems that the email field doesn't matter.

@GalaxySnail

Copy link
Copy Markdown
Author

/preview

@gitgitgadget-git

Copy link
Copy Markdown

Preview email sent as pull.2362.git.git.1784797499312.gitgitgadget@gmail.com

@dscho

dscho commented Jul 23, 2026

Copy link
Copy Markdown
Member

Thanks! I have set my name in the user profile now. However, although I have already set my public email to me@glxys.nl, the email field in this api is still null. I also checked that the "keep my email addresses private" setting is "off". That's weird.

edit: It seems that the email field doesn't matter.

I was puzzled at first, too. Because it does matter. And the really curious thing is: GitGitGadget successfully determined your email address!

So I think that the solution to the riddle is that anonymous REST API requests don't get that email field filled, whereas GitGitGadget issues an authenticated request, which does get that information.

@GalaxySnail

Copy link
Copy Markdown
Author

So I think that the solution to the riddle is that anonymous REST API requests don't get that email field filled, whereas GitGitGadget issues an authenticated request, which does get that information.

That makes sense, thank you for the explanation!

By default, libcurl uses a 300 seconds timeout for the connection phase,
which is too long for some use cases.

Add http.connecttimeoutms and GIT_HTTP_CONNECT_TIMEOUT_MS to specify
timeout in milliseconds for the connection phase. Both of them call
CURLOPT_CONNECTTIMEOUT_MS internally.

Signed-off-by: GalaxySnail <me@glxys.nl>
@GalaxySnail
GalaxySnail force-pushed the http-connect-timeout-ms branch from 47457be to 1b65c31 Compare July 23, 2026 09:18
@GalaxySnail

Copy link
Copy Markdown
Author

/preview

@GalaxySnail
GalaxySnail force-pushed the http-connect-timeout-ms branch from 1b65c31 to b335e39 Compare July 23, 2026 09:20
@gitgitgadget-git

Copy link
Copy Markdown

Preview email sent as pull.2362.git.git.1784798473143.gitgitgadget@gmail.com

@GalaxySnail

Copy link
Copy Markdown
Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2362.git.git.1784798733557.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2362/GalaxySnail/http-connect-timeout-ms-v1

To fetch this version to local tag pr-git-2362/GalaxySnail/http-connect-timeout-ms-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2362/GalaxySnail/http-connect-timeout-ms-v1

@gitgitgadget-git

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"GalaxySnail via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: GalaxySnail <me@glxys.nl>
>
> By default, libcurl uses a 300 seconds timeout for the connection phase,
> which is too long for some use cases.

Can you elaborate a bit more on the use cases in which you want to
try connecting to an unreachable host yet want to give up on it very
fast?

> Add http.connecttimeoutms and GIT_HTTP_CONNECT_TIMEOUT_MS to specify
> timeout in milliseconds for the connection phase. Both of them call
> CURLOPT_CONNECTTIMEOUT_MS internally.
>
> Signed-off-by: GalaxySnail <me@glxys.nl>

Documentation/SubmittingPatches:[[real-name]] applies here.

>  Documentation/config/http.adoc  |  7 ++++
>  http.c                          | 11 ++++++
>  t/meson.build                   |  1 +
>  t/t5585-http-connect-timeout.sh | 60 +++++++++++++++++++++++++++++++++
>  4 files changed, 79 insertions(+)
>  create mode 100755 t/t5585-http-connect-timeout.sh
>
> diff --git a/Documentation/config/http.adoc b/Documentation/config/http.adoc
> index 792a71b413..a4f7afa61e 100644
> --- a/Documentation/config/http.adoc
> +++ b/Documentation/config/http.adoc
> @@ -300,6 +300,13 @@ for most push problems, but can increase memory consumption
>  significantly since the entire buffer is allocated even for small
>  pushes.
>  
> +http.connectTimeoutMS::
> +	Maximum time in milliseconds that you allow the connection phase
> +	to take. The connection phase includes DNS lookup and subsequent
> +	TCP, TLS or QUIC handshakes.
> +	Can be overridden by the `GIT_HTTP_CONNECT_TIMEOUT_MS`
> +	environment variable.

Once a knob is provided, users will want to know what value is
used when unspecified, so they can gauge what a reasonable value to
set would be.

> diff --git a/http.c b/http.c
> index caccf2108e..befe9ea8a0 100644
> --- a/http.c
> +++ b/http.c
> @@ -68,6 +68,7 @@ static char *ssl_capath;
>  static char *curl_no_proxy;
>  static char *ssl_pinnedkey;
>  static char *ssl_cainfo;
> +static long curl_connect_timeout_ms = -1;
>  static long curl_low_speed_limit = -1;
>  static long curl_low_speed_time = -1;
>  static int curl_ftp_no_epsv;
> @@ -450,6 +451,10 @@ static int http_options(const char *var, const char *value,
>  		max_requests = git_config_int(var, value, ctx->kvi);
>  		return 0;
>  	}
> +	if (!strcmp("http.connecttimeoutms", var)) {
> +		curl_connect_timeout_ms = git_config_int(var, value, ctx->kvi);
> +		return 0;
> +	}

We could set it to -1 if we wanted to, and behave as if no
configuration variable were given.  That may be reasonable, but it
should be documented.

> @@ -1215,6 +1220,10 @@ static CURL *get_curl_handle(void)
>  			curl_easy_setopt(result, CURLOPT_PROXY_CAINFO, http_proxy_ssl_ca_info);
>  	}
>  
> +	if (curl_connect_timeout_ms > 0)
> +		curl_easy_setopt(result, CURLOPT_CONNECTTIMEOUT_MS,
> +				 curl_connect_timeout_ms);

This code silently ignores setting the configuration variable to 0.
To the cURL library, however, passing a value of 0 to
CURLOPT_CONNECTTIMEOUT_MS signals that it should use the default
value (300s).

Perhaps we should tweak the above to

	if (0 <= curlopt_connecttimeout_ms)
		curl_easy_setopt(result, CURLOPT_CONNECTTIMEOUT_MS,
				 curl_connect_timeout_ms);

and then document what 0 means.

> @@ -1474,6 +1483,8 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
>  
>  	set_from_env(&user_agent, "GIT_HTTP_USER_AGENT");
>  
> +	set_long_from_env(&curl_connect_timeout_ms, "GIT_HTTP_CONNECT_TIMEOUT_MS");
> +
>  	set_long_from_env(&curl_low_speed_limit, "GIT_HTTP_LOW_SPEED_LIMIT");
>  	set_long_from_env(&curl_low_speed_time, "GIT_HTTP_LOW_SPEED_TIME");

This, along with other environment variables, is processed after
repo_config() collects configured values by triggering the
http_options() callback, so the environment overrides the configured
value, as expected.

> diff --git a/t/t5585-http-connect-timeout.sh b/t/t5585-http-connect-timeout.sh
> new file mode 100755
> index 0000000000..7363e23bfe
> --- /dev/null
> +++ b/t/t5585-http-connect-timeout.sh
> @@ -0,0 +1,60 @@
> +#!/bin/sh
> +
> +test_description='test http.connecttimeoutms and GIT_HTTP_CONNECT_TIMEOUT_MS'
> +
> +. ./test-lib.sh
> +. "$TEST_DIRECTORY"/lib-httpd.sh
> +start_httpd

What are we testing with this new script, really?

As far as I can see, nobody is sitting next to the running test
with a stopwatch to ensure that the client times out as specified.  Should
we really consume a limited shared resource, the four-digit test
number, for this instead of adding a few "not a number (should fail
to parse)" tests to existing http tests?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants