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

getaddrinfo() thread failed on HPUX #2697

Closed
Eason-Yu opened this Issue Jun 29, 2018 · 20 comments

Comments

Projects
None yet
3 participants
@Eason-Yu

Eason-Yu commented Jun 29, 2018

I build curl-7.60.0 on HPUX by running "configure && make && sudo make install", then run the following command:
bash-3.1# /usr/local/bin/curl -x dcmfa02-w2k16d.mfa.cdc:8080 --connect-timeout 5 URL -v 2>&1

  • getaddrinfo() thread failed to start

  • Couldn't resolve proxy 'dcmfa02-w2k16d.mfa.cdc'

  • Closing connection 0
    curl: (5) getaddrinfo() thread failed to start`

get a error "getaddrinfo() thread failed to start", then check the lib dependency of curl, pthread lib is not there.

Btw, using LD_PRELOAD specify with pthread lib, then it works well. details as follows:
bash-3.1# LD_PRELOAD=/usr/lib/libpthread.1 /usr/local/bin/curl -x dcmfa02-w2k16d.mfa.cdc:8080 --connect-timeout 5 URL -v 2>&1

  • Trying 10.100.50.50...
  • TCP_NODELAY set
  • Connected to dcmfa02-w2k16d.mfa.cdc (10.100.50.50) port 8080 (#0)
  • allocate connect buffer!
  • Establish HTTP proxy tunnel to xxx

CONNECT xxx HTTP/1.1
Host: xxx
User-Agent: curl/7.60.0
Proxy-Connection: Keep-Alive

< HTTP/1.1 200 Connection established
<

@bagder bagder added the build label Jun 29, 2018

@bagder

This comment has been minimized.

Member

bagder commented Jun 29, 2018

First, I note that the last curl release is provided as binary builds for HPUX by others so clearly it builds and works for some: https://curl.haxx.se/download.html#HPUX

To me this sounds like something in your run-time environment makes it not find and use the pthread library and since configure both deemed it present and made use of it, this problem will prevent curl from working correctly.

@Eason-Yu

This comment has been minimized.

Eason-Yu commented Jun 30, 2018

But I use the same commands to build it on RHEL, AIX and Solaris, curl can work well. Just curious why it just can not work on HPUX, seems the building for curl on HPUX needs a different configuration option (e.g. ./configure LIBS="-lpthread"), if so, i think at least curl needs give a doc for it.

@bagder

This comment has been minimized.

Member

bagder commented Jun 30, 2018

configure already checks for your pthreads library and if it fails to find it, it won't enable the threaded resolver in the first place.

This makes me believe configure found it for you and made use of it correctly (configure's output and even the config.log can confirm that), but then when you use built output, something in your environment makes it not work run-time.

@bagder bagder added the name lookup label Jun 30, 2018

@bagder bagder changed the title from curl can not work on HPUX to getaddrinfo() thread failed on HPUX Jun 30, 2018

@Eason-Yu

This comment has been minimized.

Eason-Yu commented Jun 30, 2018

yes. configure check pthread and find it. But library pthread is not linked into curl on HPUX. Do you try to build the latest version of curl on HPUX? If you did, is library pthread included into the library dependencies of curl?

@bagder

This comment has been minimized.

Member

bagder commented Jun 30, 2018

yes. configure check pthread and find it. But library pthread is not linked into curl on HPUX.

Can you please show how this happens by pasting/including the relevant bits from the output or config.log file?

Do you try to build the latest version of curl on HPUX?

No I don't. I'm still willing to help you nail down this problem and if necessary adjust things to make them work better. To do that, I must first understand what fails with the existing configure logic.

@Eason-Yu

This comment has been minimized.

Eason-Yu commented Jun 30, 2018

I run "configure; make; make install" to build curl, no error occurs except for the following warning during make:
libtool: warning: this platform does not like uninstalled shared libraries
libtool: warning: 'curl' will be relinked during installation

then i check the lib dependencies of curl, pthread is not there. then i gdb debug curl, and found pthread_create always fail, and return errno 251 (function is not available).

Note: Redhat, Solaris and AIX does not have this issue, and pthread is included into the lib dependencies of the curl on those platforms. just curious, i run the same command, why lib pthread is no t included into the lib dependencies of curl on HPUX.

@bagder

This comment has been minimized.

Member

bagder commented Jun 30, 2018

So I ask again:

Can you please show how this happens by pasting/including the relevant bits from the configure output or config.log file?

@Eason-Yu

This comment has been minimized.

Eason-Yu commented Jul 1, 2018

Please check config.log. Thanks.

BTW, want to confirm with you for the following snippet of configure
...
if test "x$ac_cv_func_pthread_create" = xyes; then :
USE_THREADS_POSIX=1
fi

if test "$USE_THREADS_POSIX" != "1" <====== Should it be "$USE_THREADS_POSIX" = 1?
then
CFLAGS="$CFLAGS -pthread"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5
$as_echo_n "checking for pthread_create in -lpthread... " >&6; }
if ${ac_cv_lib_pthread_pthread_create+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
...

@bagder

This comment has been minimized.

Member

bagder commented Jul 1, 2018

if test "$USE_THREADS_POSIX" != "1" <====== Should it be "$USE_THREADS_POSIX" = 1?

No. That check is there to see if it isn't enabled yet and if so, do some additional checks. This code

But what's curious about your config.log is that when configure checks if it can find and use pthread_create without any additional libraries provided, it succeeds! (line 60037 of your attached log file). Since it actually works to build a program using that function without any additional libs it is of course deemed unnecessary to add one. What puzzles me is of course why this works (and it also doesn't cause any link errors when you then go on to build curl which then uses the pthread functions)... and you only get the problems at run-time. Can you understand why this is so?

@Eason-Yu

This comment has been minimized.

Eason-Yu commented Jul 1, 2018

I'm not sure. But I suspect the checking for pthread_create. line 60037 just tell the conftest is built successfully, but it does not tell if pthread_create is available or not.
I wrote a small test program (e.g. conftest.c) on HPUX, as follows:
#include <pthread.h> int main (void) { return pthread_create (NULL, NULL,, NULL, NULL); }
$ gcc -o conftest conftest.c <<<===== No link errors.
$ ./conftest
$ echo $?
251

I have checked this issue for two days, and i'm not familiar with the building. If you have a HPUX, i think it should be able to be reproduced easily.

@bagder

This comment has been minimized.

Member

bagder commented Jul 1, 2018

line 60037 just tell the conftest is built successfully, but it does not tell if pthread_create is available or not

That's not how linking generally works. The linker should check that the functions are available! This is clearly the reason why the pthread check fails on this system...

I don't have an HPUX system and I never had. I logged into one though, once. Like 17 years ago or so...

@Eason-Yu

This comment has been minimized.

Eason-Yu commented Jul 2, 2018

Google a lot. Found the reason pthread_create is failing with error 251 is the libc library provides stubs for the pthread functions on HPUX. So no link error does not mean you don't need to link pthread library on HPUX.

Do you think you (configure.ac) should deal with this exception on HPUX? If so, can you provide me a patch for this issue?

@bagder

This comment has been minimized.

Member

bagder commented Jul 2, 2018

can you provide me a patch for this issue?

Can you try this patch and see if this works for you? It's a bit "crude" as it checks fox hpux specifically, but I really can't figure out a really nice way to do this.

You need to apply the patch and run ./buildconf, then you can run configure again.

--- a/configure.ac
+++ b/configure.ac
@@ -3779,10 +3779,20 @@ if test "$want_pthreads" != "no"; then
       save_CFLAGS="$CFLAGS"
 
       dnl first check for function without lib
       AC_CHECK_FUNC(pthread_create, [USE_THREADS_POSIX=1] )
 
+      dnl on HPUX, life is more complicated...
+      case $host in
+      *-hp-hpux*)
+         dnl it doesn't actually work without -lpthread
+         USE_THREADS_POSIX=""
+         ;;
+      *)
+         ;;
+      esac
+
       dnl if it wasn't found without lib, search for it in pthread lib
       if test "$USE_THREADS_POSIX" != "1"
       then
         CFLAGS="$CFLAGS -pthread"
         AC_CHECK_LIB(pthread, pthread_create,
@Eason-Yu

This comment has been minimized.

Eason-Yu commented Jul 2, 2018

It's really a bit "crude". how about using AC_TRY_RUN?

@bagder

This comment has been minimized.

Member

bagder commented Jul 2, 2018

AC_TRY_RUN must be avoided as far as possible since it breaks cross-compilation. Since I rather have this "crudeness" limited to HPUX-only such a AC_TRY_RUN could be restricted to HPUX but then it seems like maybe not necessary? Do you think there's a risk different HPUX systems work differently in regards to the pthreads library?

@Eason-Yu

This comment has been minimized.

Eason-Yu commented Jul 2, 2018

I'm not sure. I would like to have a elegant way to fix it, but i'm not familiar with autoconf. So ask your help here.

@bagder

This comment has been minimized.

Member

bagder commented Jul 2, 2018

And I have no HPUX system to test on so working on an "elegant fix" is not up to me. I can't think of a proper way to fix this detection while at the same time avoiding AC_TRY_RUN, but I don't want to "hurt" all other users because of this HPUX weirdness.

An alternative would be to check if cross-compilation is being done, and only do the extra AC_TRY_RUN check if not.

@bagder

This comment has been minimized.

Member

bagder commented Aug 24, 2018

So @Eason-Yu, does the "crude" approach work at all? If so, it might be a better idea to land that than doing nothing?

@michael-o

This comment has been minimized.

Member

michael-o commented Aug 25, 2018

I might jump into this next month. I have been using HP-UX for the last 10 years, but haven't compiled curl on HP-UX for quite some time.

@Eason-Yu

This comment has been minimized.

Eason-Yu commented Aug 30, 2018

@bagder Sorry for the delay. It works. Thanks a lot.

bagder added a commit that referenced this issue Sep 21, 2018

configure: force-use -lpthreads on HPUX
When trying to detect pthreads use on HPUX the checks will succeed
without the correct -l option but then end up failing at run-time.

Reported-by: Eason-Yu on github
Fixes #2697

@bagder bagder closed this in 6f0afb8 Sep 21, 2018

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