Subject: Re: Thread safety issues

Re: Thread safety issues

From: jmk <>
Date: Mon, 30 Aug 2010 15:52:15 -0500

On Mon, 2010-08-30 at 15:51 +0200, Daniel Stenberg wrote:
> On Mon, 30 Aug 2010, Jose Baars wrote:
> > Wouldn't the libssh2_init function be one of the prime suspects? This
> > function was added in libssh2 1.2.7.
> Quoted from the man page for libssh2_init():
> It uses a global state, and is not thread safe -- you must
> make sure this function is not called concurrently.
> ... and before anyone questions the reasoning for this let me exaplain that
> the underlying libraries (OpenSSL or libgcrypt) both have non thread-safe init
> functions themselves that libssh2 need to use.

I've added a mutex lock around libssh2_session_init_ex(). This
drastically cut down on it blowing up. However, it appears that some of
the other functions may also have thread safety issues. Specifically, I
had to also lock libssh2_userauth_keyboard_interactive() and
libssh2_session_free(). With all libssh2_* calls locked, I've been
unable to get it to blow up. Certainly not ideal, but better than the
alternative for now.


Received on 2010-08-30