Subject: Re: multithread calls libssh2_session_handshake,error,return -13

Re: multithread calls libssh2_session_handshake,error,return -13

From: Michael Kwasigroch <>
Date: Thu, 13 Feb 2014 10:28:41 +0100


(@ALL: sorry to hitchhike this thread)

in your configure call you use --with-XXX-prefix - this never worked for
me, neither in the stable nor the development versions of libssh2 on AIX,
Solaris and Linux.

Have you checked that the compiled was actually linked to the
shlibs in $HOME/...?

I still suspect that --with-XXX-prefix does not work in libssh2. The build
process always used the standard libs located in /usr/lib (or /usr/lib64
etc.) regardless of the settings of --with-XXX-prefix.

If you find the same we may get on to find and fix it (or file a bug
report for the configure experts).


Mit freundlichen Gruessen / best regards

Michael Kwasigroch

Office number: +49 40 514 52-175
Office fax: +49 40 514 52-100

From: Alfred Gebert <>
To: libssh2 development <>
Date: 13.02.2014 09:16
Subject: Re: multithread calls
libssh2_session_handshake,error,return -13
Sent by: "libssh2-devel" <>

On Wed, Feb 12, 2014 at 4:10 AM, xingzhiming <>
> hi,all
> When using multiple threads, in libssh2_session_handshake abnormal.
> If you do not multi-threaded, no problem. How to use multi-thread
calls libssh2?

I had a similar problem. Perhaps my solution can you help as well.

If I created a session I got the error:
  Unable to exchange encryption keys

I enabled verbose logging and did run the application with truss
(similar to strace on Linux) on Solaris.

  /13: recv(11, 0xFFFFFD7FFBA05B17, 1, 0) Err#11 EAGAIN
  _libssh2_recv: rc=-1 errno=125
  [libssh2] 0.758411 Socket: Error recving 1 bytes: 125

On the first line above a recv() system call returned with -1 and
errno was 11 (EAGAIN). But on the second and third line errno was 125.
The second line is a debug output which I added to the source directly
after the recv() statement.

The source of the problem was that I didn't compile libssh2 with
correct compiler flags for multi-threading. If you do not pay
attention on Solaris then errno is a global variable. Using gcc
compiler you can add "-pthread" as compile and link flag to enable
thread local storage of errno. Using -D_REENTRANT on Solaris as
compile flag also works. My configure call is now is e.g.
  CFLAGS="-m64 -pthread" LDFLAGS="-m64 -pthread" ./configure
--with-openssl --with-libssl-prefix=$HOME/local --with-libz
--with-libz-prefix=$HOME/local --prefix=$HOME/local

INTERCOPE International Communication Products Engineering GmbH
Himmelstrasse 12-16, 22299 Hamburg, Germany
Managing Directors: Reinhart Laumer, Frank Kollender
Commercial Registry: Amtsgericht Hamburg, HRB 31 638
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

Received on 2014-02-13