{"thread":{"id":"41969","subject":"git 2.8.1 not working with socks5h https proxy anymore","startedAt":"2016-04-08T18:46:08Z","lastAt":"2016-04-10T18:11:40Z","messageCount":5,"participants":["Felix Ruess","Dennis Kaarsemaker","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"282976","messageId":"CAEc+GFeG-ZdeTXGsjmwV0QP6QwYvjA4nzCGitka0aXjqEkatfg@mail.gmail.com","threadId":"41969","inReplyTo":null,"subject":"git 2.8.1 not working with socks5h https proxy anymore","fromName":"Felix Ruess","fromEmail":"felix.ruess@gmail.com","sentAt":"2016-04-08T18:46:08Z","receivedAt":"2016-04-08T18:46:08Z","isPatch":false,"sender":{"key":"felix.ruess@gmail.com","avatar":null},"body":"Hi all,\n\nI just encountered a problem with the latest git version (2.8.1) that\nlooks like a regression to me:\nWhen trying to clone a repo via a https socks5 proxy the connection times out:\n\n$ git config --global 'http.proxy=socks5h://127.0.0.1:1080'\n$ export GIT_CURL_VERBOSE=1\n$ git clone https://foo.de/bar.git\nCloning into 'bar'...\n* Couldn't find host foo.de in the .netrc file; using defaults\n* Hostname was NOT found in DNS cache\n*   Trying 127.0.0.1...\n* Hostname was NOT found in DNS cache\n* 80\n* 147\n* 201\n* 194\nchannel 2: open failed: connect failed: Connection timed out\nchannel 4: open failed: connect failed: Connection timed out\n* Failed to receive SOCKS5 connect request ack.\n* Closing connection 0\nfatal: unable to access 'https://foo.de/bar.git/': Failed to receive\nSOCKS5 connect request ack.\n\nI'm on Ubuntu 14.04 64bit and it works perfectly fine with git 1.9.1\n(and was also working with older git 2.x versions, although not sure\nany more what the last working version was).\n\nCheers, Felix\n"},{"id":"282977","messageId":"1460142453.32486.2.camel@kaarsemaker.net","threadId":"41969","inReplyTo":"CAEc+GFeG-ZdeTXGsjmwV0QP6QwYvjA4nzCGitka0aXjqEkatfg@mail.gmail.com","subject":"Re: git 2.8.1 not working with socks5h https proxy anymore","fromName":"Dennis Kaarsemaker","fromEmail":"dennis@kaarsemaker.net","sentAt":"2016-04-08T19:07:33Z","receivedAt":"2016-04-08T19:07:33Z","isPatch":false,"sender":{"key":"dennis@kaarsemaker.net","avatar":"https://avatars.githubusercontent.com/u/200649?v=4"},"body":"On vr, 2016-04-08 at 20:46 +0200, Felix Ruess wrote:\n> Hi all,\n> \n> I just encountered a problem with the latest git version (2.8.1) that\n> looks like a regression to me:\n> When trying to clone a repo via a https socks5 proxy the connection\n> times out:\n> \n> $ git config --global 'http.proxy=socks5h://127.0.0.1:1080'\n> $ export GIT_CURL_VERBOSE=1\n> $ git clone https://foo.de/bar.git\n> Cloning into 'bar'...\n> * Couldn't find host foo.de in the .netrc file; using defaults\n> * Hostname was NOT found in DNS cache\n> *   Trying 127.0.0.1...\n> * Hostname was NOT found in DNS cache\n> * 80\n> * 147\n> * 201\n> * 194\n> channel 2: open failed: connect failed: Connection timed out\n> channel 4: open failed: connect failed: Connection timed out\n> * Failed to receive SOCKS5 connect request ack.\n> * Closing connection 0\n> fatal: unable to access 'https://foo.de/bar.git/': Failed to receive\n> SOCKS5 connect request ack.\n> \n> I'm on Ubuntu 14.04 64bit and it works perfectly fine with git 1.9.1\n> (and was also working with older git 2.x versions, although not sure\n> any more what the last working version was).\n\nI think that's 6d7afe07f29df75f831a46fb0f657fa37e561779, which\ninterprets that as a socks5 proxy.\n\nI think this should fix it (but haven't tested it beyond 'it\ncompiles'):\n\ndiff --git a/http.c b/http.c\nindex 69da445..4304b80 100644\n--- a/http.c\n+++ b/http.c\n@@ -605,7 +605,10 @@ static CURL *get_curl_handle(void)\n \tif (curl_http_proxy) {\n \t\tcurl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);\n #if LIBCURL_VERSION_NUM >= 0x071800\n-\t\tif (starts_with(curl_http_proxy, \"socks5\"))\n+\t\tif (starts_with(curl_http_proxy, \"socks5h\"))\n+\t\t\tcurl_easy_setopt(result,\n+\t\t\t\tCURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);\n+\t\telse if (starts_with(curl_http_proxy, \"socks5\"))\n \t\t\tcurl_easy_setopt(result,\n \t\t\t\tCURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);\n \t\telse if (starts_with(curl_http_proxy, \"socks4a\"))\n\nBut I have no socks5h proxy to test with. Can you give this patch a spin?\n-- \nDennis Kaarsemaker\nwww.kaarsemaker.net\n"},{"id":"282978","messageId":"xmqq8u0nx66h.fsf@gitster.mtv.corp.google.com","threadId":"41969","inReplyTo":"CAEc+GFeG-ZdeTXGsjmwV0QP6QwYvjA4nzCGitka0aXjqEkatfg@mail.gmail.com","subject":"Re: git 2.8.1 not working with socks5h https proxy anymore","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-08T19:16:06Z","receivedAt":"2016-04-08T19:16:06Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felix Ruess <felix.ruess@gmail.com> writes:\n\n> I just encountered a problem with the latest git version (2.8.1) that\n> looks like a regression to me:\n> When trying to clone a repo via a https socks5 proxy the connection times out:\n>\n> $ git config --global 'http.proxy=socks5h://127.0.0.1:1080'\n\nThe first version of Git that has code that explicitly supports\nsocks proxy is 2.6.4, it seems.  Since then we have always used\nCURLPROXY_SOCKS5 for curl_http_proxy that begins with a string\n\"socks5\".\n\nChecking\n\n    https://github.com/curl/curl/blob/master/docs/libcurl/symbols-in-versions\n\nI find that that at curl 7.18.0, curl added a separate\nCURLPROXY_SOCKS5_HOSTNAME that can be triggered by \"socks5h:\" that\nis separate from CURLPROXY_SOCKS5, and I am guessing that the\ndifferences in behaviour between these two is what is causing you\ntrouble.  https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html says\n\n  ..., socks5h:// (the last one to enable socks5 and asking the proxy\n  to do the resolving, also known as CURLPROXY_SOCKS5_HOSTNAME type)\n\nand because not using _HOSTNAME variant would likely not ask the\nproxy to do the resolving, it explains the stall on your end, if\nyour box cannot resolve external hostname.\n\nPerhaps the attached patch may help?\n\nI do not know if Pat is still active as a developer, but I am\nwondering what the reason was to use starts_with(..., \"socks5\")\ninstead of \"socks5:\", \"socks4a:\", etc. when identifying the proxy\ntype.\n\n http.c | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/http.c b/http.c\nindex 69da445..4304b80 100644\n--- a/http.c\n+++ b/http.c\n@@ -605,7 +605,10 @@ static CURL *get_curl_handle(void)\n \tif (curl_http_proxy) {\n \t\tcurl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);\n #if LIBCURL_VERSION_NUM >= 0x071800\n-\t\tif (starts_with(curl_http_proxy, \"socks5\"))\n+\t\tif (starts_with(curl_http_proxy, \"socks5h\"))\n+\t\t\tcurl_easy_setopt(result,\n+\t\t\t\tCURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);\n+\t\telse if (starts_with(curl_http_proxy, \"socks5\"))\n \t\t\tcurl_easy_setopt(result,\n \t\t\t\tCURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);\n \t\telse if (starts_with(curl_http_proxy, \"socks4a\"))\n"},{"id":"283012","messageId":"CAEc+GFerpBC_O4jMvtmUhVdLReEN4nvuz5Q30SFUp8qZnQZBmQ@mail.gmail.com","threadId":"41969","inReplyTo":"xmqq8u0nx66h.fsf@gitster.mtv.corp.google.com","subject":"Re: git 2.8.1 not working with socks5h https proxy anymore","fromName":"Felix Ruess","fromEmail":"felix.ruess@gmail.com","sentAt":"2016-04-09T12:05:11Z","receivedAt":"2016-04-09T12:05:11Z","isPatch":false,"sender":{"key":"felix.ruess@gmail.com","avatar":null},"body":"Thanks a lot!\nTested the patch and it works as expected :-)\n\nOn Fri, Apr 8, 2016 at 9:16 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Felix Ruess <felix.ruess@gmail.com> writes:\n>\n>> I just encountered a problem with the latest git version (2.8.1) that\n>> looks like a regression to me:\n>> When trying to clone a repo via a https socks5 proxy the connection times out:\n>>\n>> $ git config --global 'http.proxy=socks5h://127.0.0.1:1080'\n>\n> The first version of Git that has code that explicitly supports\n> socks proxy is 2.6.4, it seems.  Since then we have always used\n> CURLPROXY_SOCKS5 for curl_http_proxy that begins with a string\n> \"socks5\".\n>\n> Checking\n>\n>     https://github.com/curl/curl/blob/master/docs/libcurl/symbols-in-versions\n>\n> I find that that at curl 7.18.0, curl added a separate\n> CURLPROXY_SOCKS5_HOSTNAME that can be triggered by \"socks5h:\" that\n> is separate from CURLPROXY_SOCKS5, and I am guessing that the\n> differences in behaviour between these two is what is causing you\n> trouble.  https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html says\n>\n>   ..., socks5h:// (the last one to enable socks5 and asking the proxy\n>   to do the resolving, also known as CURLPROXY_SOCKS5_HOSTNAME type)\n>\n> and because not using _HOSTNAME variant would likely not ask the\n> proxy to do the resolving, it explains the stall on your end, if\n> your box cannot resolve external hostname.\n>\n> Perhaps the attached patch may help?\n>\n> I do not know if Pat is still active as a developer, but I am\n> wondering what the reason was to use starts_with(..., \"socks5\")\n> instead of \"socks5:\", \"socks4a:\", etc. when identifying the proxy\n> type.\n>\n>  http.c | 5 ++++-\n>  1 file changed, 4 insertions(+), 1 deletion(-)\n>\n> diff --git a/http.c b/http.c\n> index 69da445..4304b80 100644\n> --- a/http.c\n> +++ b/http.c\n> @@ -605,7 +605,10 @@ static CURL *get_curl_handle(void)\n>         if (curl_http_proxy) {\n>                 curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);\n>  #if LIBCURL_VERSION_NUM >= 0x071800\n> -               if (starts_with(curl_http_proxy, \"socks5\"))\n> +               if (starts_with(curl_http_proxy, \"socks5h\"))\n> +                       curl_easy_setopt(result,\n> +                               CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);\n> +               else if (starts_with(curl_http_proxy, \"socks5\"))\n>                         curl_easy_setopt(result,\n>                                 CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);\n>                 else if (starts_with(curl_http_proxy, \"socks4a\"))\n"},{"id":"283107","messageId":"xmqqegadtjtv.fsf@gitster.mtv.corp.google.com","threadId":"41969","inReplyTo":"CAEc+GFerpBC_O4jMvtmUhVdLReEN4nvuz5Q30SFUp8qZnQZBmQ@mail.gmail.com","subject":"Re: git 2.8.1 not working with socks5h https proxy anymore","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-10T18:11:40Z","receivedAt":"2016-04-10T18:11:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felix Ruess <felix.ruess@gmail.com> writes:\n\n> Thanks a lot!\n> Tested the patch and it works as expected :-)\n\nThanks, lets do this, then.\n\n-- >8 --\nSubject: [PATCH] http: differentiate socks5:// and socks5h://\n\nFelix Ruess <felix.ruess@gmail.com> noticed that with configuration\n\n    $ git config --global 'http.proxy=socks5h://127.0.0.1:1080'\n\nconnections to remote sites time out, waiting for DNS resolution.\n\nThe logic to detect various flavours of SOCKS proxy and ask the\nlibcurl layer to use appropriate one understands the proxy string\nthat begin with socks5, socks4a, etc., but does not know socks5h,\nand we end up using CURLPROXY_SOCKS5.  The correct one to use is\nCURLPROXY_SOCKS5_HOSTNAME.\n\nhttps://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html says\n\n  ..., socks5h:// (the last one to enable socks5 and asking the\n  proxy to do the resolving, also known as CURLPROXY_SOCKS5_HOSTNAME\n  type).\n\nwhich is consistent with the way the breakage was reported.\n\nTested-by: Felix Ruess <felix.ruess@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n http.c | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/http.c b/http.c\nindex c29ce81..b560c13 100644\n--- a/http.c\n+++ b/http.c\n@@ -466,7 +466,10 @@ static CURL *get_curl_handle(void)\n \tif (curl_http_proxy) {\n \t\tcurl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);\n #if LIBCURL_VERSION_NUM >= 0x071800\n-\t\tif (starts_with(curl_http_proxy, \"socks5\"))\n+\t\tif (starts_with(curl_http_proxy, \"socks5h\"))\n+\t\t\tcurl_easy_setopt(result,\n+\t\t\t\tCURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);\n+\t\telse if (starts_with(curl_http_proxy, \"socks5\"))\n \t\t\tcurl_easy_setopt(result,\n \t\t\t\tCURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);\n \t\telse if (starts_with(curl_http_proxy, \"socks4a\"))\n-- \n2.8.1-339-gc925d85\n"}]}