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

libcurl 7.88.0- getaddrinfo() thread failed to start #10561

Closed
gunamoi1 opened this issue Feb 19, 2023 · 15 comments
Closed

libcurl 7.88.0- getaddrinfo() thread failed to start #10561

gunamoi1 opened this issue Feb 19, 2023 · 15 comments
Labels
name lookup DNS and related tech Windows Windows-specific

Comments

@gunamoi1
Copy link

I use libcurl, compiled as a static library, in many of my programs.
Code written in C++, for Windows, using Visual Studio.
libcurl static library is compiled to call DLL Windows SSPI, and DLL WinIDN.
I have used all previous versions from 7.50.3 to 7.86.0, and all works great.

Recently I saw 7.88.0 is available, so I downloaded and compiled that one, using the same settings as all my previous builds.
Now all of my programs fail, with a message:
"getaddrinfo() thread failed to start".

So, I have gone back to using the previous version 7.86.0, and all my programs work again.

What might be causing this bug in 7.88.0?
Is there some extra curl setup required in this new version which I will have to change in my programs to make them work with 7.88.0?

@jay jay added Windows Windows-specific name lookup DNS and related tech labels Feb 19, 2023
@jay
Copy link
Member

jay commented Feb 19, 2023

Ref: #6495
Ref: #10144

Possible resource issue or MITM issue. Allowing MITM was supposed to be fixed in 7.88.0 unless that broke something for you. Does it work if you use the curl tool (curl.exe)? Does it happen 100% of the time? If you go back to 7.86 does it work? If you git checkout curl-7_88_0 and then revert 7fa449c does it work? Do you have an anti-virus client that could be interfering?

You could further narrow it down by bisecting. The 'Build but no install' step is specific to autotools builds so ignore it in this case. Since you are using a VS project configuration (eg 'DLL Release - DLL Windows SSPI - DLL WinIDN') your 'Build but no install' step would be run generate.bat <vcver> (eg generate vc14.30) from the projects directory then build the configuration in Visual Studio.

edit: I checked out curl-7_88_0 and built 'LIB Release - DLL Windows SSPI - DLL WinIDN' in VS2022 and ran curl https://www.google.com in Windows 7 and 11 without issue.

@u20221022
Copy link

u20221022 commented Feb 19, 2023

Does it work if you use the curl tool (curl.exe)? Does it happen 100% of the time? … Do you have an anti-virus client that could be interfering?

I got the same message in command line a few hours ago when I was preparing examples for #10558.
Only once. MS Windows Defender only. MS Windows 10.

Update: resource – fake curl1.se, curl2.se, etc only.
Sorry, I have already closed that window of Cmd.exe.

Update2: Sorry, it was not Cmd.exe, it was PowerShell.
getaddrinfo

@jay
Copy link
Member

jay commented Feb 19, 2023

I have been able to reproduce approx every twenty minutes but only in certain circumstances. No debugging or printfs. OutputDebugString ok though. I run the same command repeatedly in a batch file, with apologies to the apache folks, until it fails:

(edit: refer to jay:curl:win32_debug_socketpair_init instead for a faster and complete repeat.bat)

FOR /L %%G IN (1,1,%MAX%) DO (
  curld -sS -f -H "Connection: close" https://httpd.apache.org/ -o NUL --write-out "%%{time_total} "
  if !ERRORLEVEL! NEQ 0 exit /b 1
)

It looks like it is related to 7fa449c.

curl/lib/socketpair.c

Lines 118 to 124 in 41dfb7f

/* write data to the socket */
swrite(socks[0], &now, sizeof(now));
/* verify that we read the correct data */
if((sizeof(now) != sread(socks[1], &check, sizeof(check)) ||
memcmp(&now, &check, sizeof(check))))
goto error;
}

sread returns SOCKET_ERROR and WSAGetLastError returns WSAEWOULDBLOCK. The socket is non-blocking so we will have to take into account that sread/recv (and to a lesser extent swrite/send) may return this. @bagder

@u20221022
Copy link

MITM at fake addresses curl1.se/curl2.se/…?
And why error №6 («Could not resolve host.»), not №2 («Failed to initialize.»)?

bagder added a commit that referenced this issue Feb 19, 2023
Reported-by: Gunamoi Software
Debuggged-by: Jay Satiro
Fixes #10561
@bagder
Copy link
Member

bagder commented Feb 19, 2023

@gunamoi1 does #10562 fix the issue for you?

@renodr
Copy link
Contributor

renodr commented Feb 19, 2023

Hi folks,

I was able to determine that this fixes the problem and posted my procedure/results at https://curl.se/mail/lib-2023-02/0064.html

jay added a commit to jay/curl that referenced this issue Feb 19, 2023
1. open sysinternals' dbgview

2. edit repeat.bat var CURL to path of a repo non-debug build curl.exe

3. run repeat.bat.

should repro in less than 5 min, may take 20 min, stops after 30-60 min.

~~~
curl: (6) getaddrinfo() thread failed to start
0.000000
Reproduced in 738 tries.
Ran from 15:58:20.66 to 16:00:18.40.
~~~

Ref: curl#10561 (comment)
@jay
Copy link
Member

jay commented Feb 19, 2023

Thanks for testing. It depends a lot on system resources and how many sockets are active at the same time. I've made a branch with all the debug statements that I added and a better repeat command using http://curl.se, since it is just a redirect that is not followed and therefore the transfer completes much faster making it possible to repro in less than 5 minutes here.

jay:curl:win32_debug_socketpair_init

Capture1
Capture2
Capture3

I have yet to investigate #10562

jay added a commit to jay/curl that referenced this issue Feb 19, 2023
1. open sysinternals' dbgview

2. edit repeat.bat var CURL to path of a repo non-debug build curl.exe

3. run repeat.bat.

should repro in less than 5 min, may take 20 min, stops after 30-60 min.

~~~
curl: (6) getaddrinfo() thread failed to start
0.000000
Reproduced in 738 tries.
Ran from 15:58:20.66 to 16:00:18.40.
~~~

Ref: curl#10561 (comment)
@bagder
Copy link
Member

bagder commented Feb 19, 2023

Thanks a lot @renodr!

@renodr
Copy link
Contributor

renodr commented Feb 19, 2023

Just for some followup! 😄

@jay I pulled a copy of your batch file down and edited it to go to linuxfromscratch.org (since I have access to that server) and then did a fresh build of cURL in a separate directory so that I could have a build available without #10562 applied to it.

On the unpatched build, I got the following output:

image

On the patched build, I get:

image

It ran for about an hour and 20 minutes without issues, the only reason why it stopped was because I had a network outage

I think this should be good to go! 😄

@vszakats
Copy link
Member

vszakats commented Feb 20, 2023

Test curl-for-win binaries:
https://ci.appveyor.com/api/buildjobs/tcl16t5jhb3neqdj/artifacts/all-mingw-7.88.0.zip

(disregard the version number in the filename, this is latest master + patch #10562)

Ref: https://ci.appveyor.com/project/curlorg/curl-for-win/builds/46278505

@gunamoi1
Copy link
Author

@jay
Yes, problem happens with my apps 100% of the time if compiled with 7.88.0.
If recompiled with 7.86.0, they all work perfectly.

I have only tested on one machine, Windows 10.
Even when anti-virus and firewall are disabled, v7.86 works, and v7.88.0 fails.

I downloaded a daily release, (curl-7.88.1-20230219.zip)
but that still has the same problem as 7.88.0.

@bagder
I am not a github power user.
I tried downloading and compiling #10562, (curl-bagder-socketpair-block.zip)
but get a bunch of fatal errors about missing files when I try to compile LIB Release – DLL Windows SSPI – DLL WinIDN
missing files:
..\lib\idn_win32.c
..\lib\vquic\msh3.c
..\lib\vquic\ngtcp2.c
..\lib\vquic\quiche.c
I don't get these errors when compiling the master 7.86.0, or 7.88.0, so maybe I did something wrong downloading #10562.

Anyway, based on the tests by others, it looks like your solution will probably fix my issue.
But I'll probably have to wait until it is included in a full master release to confirm myself.
regards,

@vszakats
Copy link
Member

@gunamoi1
Copy link
Author

@vszakats
Thanks, but I'm compiling into my programs as static library (LIB) not as DLL.

@bagder
I managed to get something that would compile, by starting with the contents of curl-7.88.0.zip master,
and then copying just the source files from lib and src folders of #10562 (from curl-bagder-socketpair-block.zip).
Probably just needed socketpair.c, but I copied them all anyway.

Once compiled into a static LIB and the compiled into my programs, all works good and the original problem goes away.
So, many thanks, you've definitely fixed this issue with #10562 as far as I'm concerned.

bagder added a commit that referenced this issue Feb 20, 2023
Reported-by: Gunamoi Software
Co-authored-by: Jay Satiro
Fixes #10561
Closes #10562
@ngg
Copy link
Contributor

ngg commented Feb 20, 2023

We have this same problem with 7.88.0 on some Windows machines, I'll try it with the new 7.88.1

@ngg
Copy link
Contributor

ngg commented Feb 20, 2023

We have this same problem with 7.88.0 on some Windows machines, I'll try it with the new 7.88.1

I can confirm that updating to 7.88.1 solves our issue as well.

bch pushed a commit to bch/curl that referenced this issue Jul 19, 2023
Reported-by: Gunamoi Software
Co-authored-by: Jay Satiro
Fixes curl#10561
Closes curl#10562
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
name lookup DNS and related tech Windows Windows-specific
Development

Successfully merging a pull request may close this issue.

7 participants