Help with multithreading

Enrico Tassi gareuselesinge at libero.it
Fri Aug 21 11:55:36 CEST 2009


I'm facing a problem that seems to be related to the multithreading
aspect of gnutls+curl, but digging the mailing list was not enough to
find an answer, so I'm posting hoping someone has some hints for me.

This is the way I initialize gcrypt/gnutls, and I'm doing it at the very 
beginning of the main() function:

        if (!gcry_control (GCRYCTL_ANY_INITIALIZATION_P)) {
                /* No other library has already initialized libgcrypt. */
                if (!gcry_check_version("1.2.2")) {
                        fprintf(stderr, "gcrypt version older than 1.2.2\n");
                        exit(1);
                }
                gcry_control(GCRYCTL_SET_THREAD_CBS,&gcry_threads_pthread);
                gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
                gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
        }

According to the mailing list, this should be correct. After that I call
the cURL initialization function (that is compiled against gnutls).

        curl_global_init(CURL_GLOBAL_ALL);

Here is the gdb backtrace, that seems to suggest there is something wrong with
threads (there were 2 threads, doing exactly the same, i.e. opening an SSL
connection). This is the backtrace of the thread that issued the assertion
failure:

  (gdb) core-file core 
  [New Thread 9930]
  [New Thread 9932]
  warning: Can't read pathname for load map: Input/output error.
  Reading symbols from /lib/libdl.so.2...done.
  Loaded symbols for /lib/libdl.so.2
  Reading symbols from /lib/libm.so.6...done.
  Loaded symbols for /lib/libm.so.6
  Reading symbols from /lib/libpthread.so.0...done.
  Loaded symbols for /lib/libpthread.so.0
  Reading symbols from /usr/lib/libcrypto.so.0.9.8...done.
  Loaded symbols for /usr/lib/libcrypto.so.0.9.8
  Reading symbols from /usr/lib/libcurl-gnutls.so.4...Reading symbols from /usr/lib/debug/usr/lib/libcurl-gnutls.so.4.1.1...done.
  done.
  Loaded symbols for /usr/lib/libcurl-gnutls.so.4
  Reading symbols from /usr/lib/libexpat.so.1...done.
  Loaded symbols for /usr/lib/libexpat.so.1
  Reading symbols from /lib/libc.so.6...done.
  Loaded symbols for /lib/libc.so.6
  Reading symbols from /lib64/ld-linux-x86-64.so.2...done.
  Loaded symbols for /lib64/ld-linux-x86-64.so.2
  Reading symbols from /usr/lib/libz.so.1...done.
  Loaded symbols for /usr/lib/libz.so.1
  Reading symbols from /usr/lib/libidn.so.11...done.
  Loaded symbols for /usr/lib/libidn.so.11
  Reading symbols from /usr/lib/liblber-2.4.so.2...done.
  Loaded symbols for /usr/lib/liblber-2.4.so.2
  Reading symbols from /usr/lib/libldap_r-2.4.so.2...done.
  Loaded symbols for /usr/lib/libldap_r-2.4.so.2
  Reading symbols from /lib/librt.so.1...done.
  Loaded symbols for /lib/librt.so.1
  Reading symbols from /usr/lib/libgssapi_krb5.so.2...done.
  Loaded symbols for /usr/lib/libgssapi_krb5.so.2
  Reading symbols from /usr/lib/libgnutls.so.26...Reading symbols from /usr/lib/debug/usr/lib/libgnutls.so.26.14.10...done.
  done.
  Loaded symbols for /usr/lib/libgnutls.so.26
  Reading symbols from /usr/lib/libgcrypt.so.11...Reading symbols from /usr/lib/debug/usr/lib/libgcrypt.so.11.5.2...done.
  done.
  Loaded symbols for /usr/lib/libgcrypt.so.11
  Reading symbols from /lib/libresolv.so.2...done.
  Loaded symbols for /lib/libresolv.so.2
  Reading symbols from /usr/lib/libsasl2.so.2...done.
  Loaded symbols for /usr/lib/libsasl2.so.2
  Reading symbols from /usr/lib/libkrb5.so.3...done.
  Loaded symbols for /usr/lib/libkrb5.so.3
  Reading symbols from /usr/lib/libk5crypto.so.3...done.
  Loaded symbols for /usr/lib/libk5crypto.so.3
  Reading symbols from /lib/libcom_err.so.2...done.
  Loaded symbols for /lib/libcom_err.so.2
  Reading symbols from /usr/lib/libkrb5support.so.0...done.
  Loaded symbols for /usr/lib/libkrb5support.so.0
  Reading symbols from /lib/libkeyutils.so.1...done.
  Loaded symbols for /lib/libkeyutils.so.1
  Reading symbols from /usr/lib/libtasn1.so.3...done.
  Loaded symbols for /usr/lib/libtasn1.so.3
  Reading symbols from /usr/lib/libgpg-error.so.0...done.
  Loaded symbols for /usr/lib/libgpg-error.so.0
  Reading symbols from /lib/libnss_files.so.2...done.
  Loaded symbols for /lib/libnss_files.so.2
  Reading symbols from /lib/libnss_mdns4_minimal.so.2...done.
  Loaded symbols for /lib/libnss_mdns4_minimal.so.2
  Reading symbols from /lib/libnss_dns.so.2...done.
  Loaded symbols for /lib/libnss_dns.so.2
  Core was generated by `freepopsd -w'.
  Program terminated with signal 6, Aborted.
  #0  0x00007f3864238d25 in raise () from /lib/libc.so.6
  (gdb) bt
  #0  0x00007f3864238d25 in raise () from /lib/libc.so.6
  #1  0x00007f386423bde1 in abort () from /lib/libc.so.6
  #2  0x00007f3864231f99 in __assert_fail () from /lib/libc.so.6
  #3  0x00007f3863024ecb in _gcry_ath_mutex_lock (lock=0x7f3863289390)
      at ath.c:193
  #4  0x00007f38630300af in md_digest_length (algorithm=1) at md.c:1070
  #5  0x00007f38632c968f in wrap_gcry_mac_output (src_ctx=0x2787110, 
      digest=0x7f3861cd87f0, digestsize=16) at mac-libgcrypt.c:150
  #6  0x00007f38632aeeb9 in _gnutls_hash_deinit (handle=0x26ca, digest=0x26cb)
      at gnutls_hash_int.c:168
  #7  0x00007f38632a6afd in _gnutls_finished (session=0x277f8d0, type=2, 
      ret=0x7f3861cd8860) at gnutls_handshake.c:231
  #8  0x00007f38632a90c1 in _gnutls_send_finished (session=0x277f8d0, 
      init=<value optimized out>) at gnutls_handshake.c:560
  #9  _gnutls_send_handshake_final (session=0x277f8d0, 
      init=<value optimized out>) at gnutls_handshake.c:2489
  #10 0x00007f38632a9315 in _gnutls_handshake_common (session=0x277f8d0)
      at gnutls_handshake.c:2693
  #11 0x00007f38632aa9f2 in gnutls_handshake (session=0x277f8d0)
      at gnutls_handshake.c:2297
  #12 0x00007f38647b0860 in handshake () from /usr/lib/libcurl-gnutls.so.4
  #13 0x00007f38647b0ed6 in Curl_gtls_connect ()
     from /usr/lib/libcurl-gnutls.so.4
  #14 0x00007f38647b1e60 in Curl_ssl_connect () from /usr/lib/libcurl-gnutls.so.4
  #15 0x00007f3864790e2c in Curl_http_connect ()
     from /usr/lib/libcurl-gnutls.so.4
  #16 0x00007f3864797072 in Curl_protocol_connect ()
     from /usr/lib/libcurl-gnutls.so.4
  #17 0x00007f3864799e24 in Curl_connect () from /usr/lib/libcurl-gnutls.so.4
  #18 0x00007f38647a551b in Curl_perform () from /usr/lib/libcurl-gnutls.so.4
  #19 0x000000000040fdc6 in luacurl_easy_perform (L=0x23f6660) at lua-curl.c:509
  #20 0x0000000000424296 in luaD_precall (L=0x23f6660, func=0x24e3640, 
      nresults=2) at ldo.c:319
  #21 0x000000000042d991 in luaV_execute (L=0x23f6660, nexeccalls=5) at lvm.c:587
  ---Type <return> to continue, or q <return> to quit---
  #22 0x0000000000424805 in luaD_call (L=0x23f6660, func=0x2430cf0, nResults=1)
      at ldo.c:377
  #23 0x0000000000423ea7 in luaD_rawrunprotected (L=0x23f6660, 
      f=0x4218e0 <f_call>, ud=0x7f3861cd8f10) at ldo.c:116
  #24 0x0000000000423f25 in luaD_pcall (L=0x26ca, func=0x26cb, u=0x6, 
      old_top=-1, ef=41385872) at ldo.c:461
  #25 0x0000000000421722 in lua_pcall (L=0x23f6660, nargs=2, nresults=1, 
      errfunc=<value optimized out>) at lapi.c:817
  #26 0x00000000004205d1 in luay_call (s=0x23f6660, args=0x43acee "ps|d", 
      funcname=0x43ace9 "pass") at luay.c:282
  #27 0x000000000040a9e2 in freepops_pass (p=0x23f6490, 
      password=0x7f3861cd98e0 "ndr") at engine.c:259
  #28 0x0000000000414026 in pop3_POPSTATE_AUTH (data=<value optimized out>)
      at popserver.c:454
  #29 pop3_thread (data=<value optimized out>) at popserver.c:785
  #30 0x00007f3864d67f9a in start_thread () from /lib/libpthread.so.0
  #31 0x00007f38642d356d in clone () from /lib/libc.so.6
  #32 0x0000000000000000 in ?? ()
  (gdb) quit

While this other thread was (sleeping?) in a poll syscall:

  #0  0x00007f38642cad36 in poll () from /lib/libc.so.6
  #1  0x00007f38647b0286 in Curl_socket_ready ()
     from /usr/lib/libcurl-gnutls.so.4
  #2  0x00007f38647b08b6 in handshake () from /usr/lib/libcurl-gnutls.so.4
  #3  0x00007f38647b0ed6 in Curl_gtls_connect ()
     from /usr/lib/libcurl-gnutls.so.4
  #4  0x00007f38647b1e60 in Curl_ssl_connect () from /usr/lib/libcurl-gnutls.so.4
  #5  0x00007f3864790e2c in Curl_http_connect ()
     from /usr/lib/libcurl-gnutls.so.4
  #6  0x00007f3864797072 in Curl_protocol_connect ()
     from /usr/lib/libcurl-gnutls.so.4
  #7  0x00007f3864799e24 in Curl_connect () from /usr/lib/libcurl-gnutls.so.4
  #8  0x00007f38647a551b in Curl_perform () from /usr/lib/libcurl-gnutls.so.4
  #9  0x000000000040fdc6 in luacurl_easy_perform (L=0x2444870) at lua-curl.c:509
  #10 0x0000000000424296 in luaD_precall (L=0x2444870, func=0x24f0b10, 
      nresults=2) at ldo.c:319
  #11 0x000000000042d991 in luaV_execute (L=0x2444870, nexeccalls=5) at lvm.c:587
  #12 0x0000000000424805 in luaD_call (L=0x2444870, func=0x247f2b0, nResults=1)
      at ldo.c:377
  #13 0x0000000000423ea7 in luaD_rawrunprotected (L=0x2444870, 
      f=0x4218e0 <f_call>, ud=0x7f38614d7f10) at ldo.c:116
  #14 0x0000000000423f25 in luaD_pcall (L=0x7f38614d78c0, func=0x2, u=0x49282, 
      old_top=-1, ef=0) at ldo.c:461
  #15 0x0000000000421722 in lua_pcall (L=0x2444870, nargs=2, nresults=1, 
      errfunc=<value optimized out>) at lapi.c:817
  #16 0x00000000004205d1 in luay_call (s=0x2444870, args=0x43acee "ps|d", 
      funcname=0x43ace9 "pass") at luay.c:282
  #17 0x000000000040a9e2 in freepops_pass (p=0x2444470, 
      password=0x7f38614d88e0 "emc2") at engine.c:259
  #18 0x0000000000414026 in pop3_POPSTATE_AUTH (data=<value optimized out>)
      at popserver.c:454
  #19 pop3_thread (data=<value optimized out>) at popserver.c:785
  #20 0x00007f3864d67f9a in start_thread () from /lib/libpthread.so.0
  #21 0x00007f38642d356d in clone () from /lib/libc.so.6

Thanks in advance
-- 
Enrico Tassi





More information about the Gnutls-devel mailing list