[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#759197: libzmq3 and libc6's 2.19-9 libpthread problems with destroying mutexes




Package: libc6
Version: 2.19-9
Severity: important
Tags: jessie
Source: glibc



After manual rebuilding libmzq3 package tests/test_conflate doesnt pass with error "Device or resource busy (mutex.hpp:94)" on jessie amd64 installation.   Manual building from sources from http://zeromq.org/ gave the same result.
Succesfull test running has been achieved only through using libpthread-2.19.so manually built http://ftp.gnu.org/gnu/glibc/glibc-2.19.tar.xz going with LD_LIBRARY_PATH setting to temporary path. Same positive result was achieved with libpthread-2.13.so from ftp://ftp.ru.debian.org/debian/pool/main/e/eglibc/libc6_2.13-38+deb7u2_amd64.deb.  At the same time test_conflate failed with libpthread-2.19.so  built by dpkg-buildpackage retrieved by "apt-get source" from debian.org repository.


Here's example where i've used for better visual custom test_conflate.cpp and mutex.hpp:

kif@nto-202:~/wrk/zmq/root/lib/x86_64-linux-gnu$ ln -s libpthread-2.19.so libpthread.so.0kif@nto-202:~/wrk/zmq/root/lib/x86_64-linux-gnu$ ls -l
total 4492
-rwxr-xr-x 1 kif kif  131107 May 27 01:24 libpthread-2.13.so      ---- from libc6_2.13-38+deb7u2_amd64.deb
-rwxr-xr-x 1 kif kif  137439 Aug 25 11:43 libpthread-2.19p.so     ---- from package built by dpkg-buildpackage from repository sources
-rwxr-xr-x 1 kif kif  137439 Aug 22 17:41 libpthread-2.19.so      ---- from /lib/x86_64-linux-gnu  from libc6
-rwxr-xr-x 1 kif kif  792677 Aug 25 09:07 libpthread-2.19s.so     ---- manually built from sources from gnu.org
lrwxrwxrwx 1 kif kif      18 Aug 25 13:06 libpthread.so.0 -> libpthread-2.19.so
lrwxrwxrwx 1 kif kif      15 Aug 25 11:56 libzmq.so -> libzmq.so.3.1.0
lrwxrwxrwx 1 kif kif      15 Aug 25 11:56 libzmq.so.3 -> libzmq.so.3.1.0
-rwxr-xr-x 1 kif kif 3390068 Aug 25 11:56 libzmq.so.3.1.0         ---- built with custom mutex.hpp for better visual


kif@nto-202:~/wrk/zmq/zeromq-4.0.4/tests/.libs$ export LD_LIBRARY_PATH=/home/kif/wrk/zmq/root/lib/x86_64-linux-gnu/ ; ldd test_conflate ; unset LD_LIBRARY_PATH
    linux-vdso.so.1 (0x00007fff09dfe000)
    libzmq.so.3 => /home/kif/wrk/zmq/root/lib/x86_64-linux-gnu/libzmq.so.3 (0x00007f96be047000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f96bde2b000)
    libpthread.so.0 => /home/kif/wrk/zmq/root/lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f96bdc0d000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f96bd902000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f96bd601000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f96bd3ea000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f96bd041000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f96be29a000)
kif@nto-202:~/wrk/zmq/zeromq-4.0.4/tests/.libs$ export LD_LIBRARY_PATH=/home/kif/wrk/zmq/root/lib/x86_64-linux-gnu/ ; ./test_conflate ; unset LD_LIBRARY_PATH
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
recieved
closed inbound
closed outbound
-------
pthread_mutex_destroy (&mutex) returned 16, errno: 156384765
Device or resource busy (mutex.hpp:94)
-------Aborted
kif@nto-202:~/wrk/zmq/zeromq-4.0.4/tests/.libs$


Changing sy
kif@nto-202:~/wrk/zmq/root/lib/x86_64-linux-gnu$ ls -l
total 4492
-rwxr-xr-x 1 kif kif  131107 May 27 01:24 libpthread-2.13.so
-rwxr-xr-x 1 kif kif  137439 Aug 25 11:43 libpthread-2.19p.so
-rwxr-xr-x 1 kif kif  137439 Aug 22 17:41 libpthread-2.19.so
-rwxr-xr-x 1 kif kif  792677 Aug 25 09:07 libpthread-2.19s.so
lrwxrwxrwx 1 kif kif      18 Aug 25 13:06 libpthread.so.0 -> libpthread-2.19.so
lrwxrwxrwx 1 kif kif      15 Aug 25 11:56 libzmq.so -> libzmq.so.3.1.0
lrwxrwxrwx 1 kif kif      15 Aug 25 11:56 libzmq.so.3 -> libzmq.so.3.1.0
-rwxr-xr-x 1 kif kif 3390068 Aug 25 11:56 libzmq.so.3.1.0
kif@nto-202:~/wrk/zmq/root/lib/x86_64-linux-gnu$ rm libpthread.so.0
kif@nto-202:~/wrk/zmq/root/lib/x86_64-linux-gnu$ ln -s libpthread-2.19s.so libpthread.so.0

kif@nto-202:~/wrk/zmq/zeromq-4.0.4/tests/.libs$ export LD_LIBRARY_PATH=/home/kif/wrk/zmq/root/lib/x86_64-linux-gnu/ ; ldd test_conflate ; unset LD_LIBRARY_PATH
    linux-vdso.so.1 (0x00007fff409fe000)
    libzmq.so.3 => /home/kif/wrk/zmq/root/lib/x86_64-linux-gnu/libzmq.so.3 (0x00007f1acc521000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f1acc305000)
    libpthread.so.0 => /home/kif/wrk/zmq/root/lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1acc0e6000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1acbddb000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1acbada000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1acb8c3000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1acb51a000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f1acc774000)
kif@nto-202:~/wrk/zmq/zeromq-4.0.4/tests/.libs$
kif@nto-202:~/wrk/zmq/zeromq-4.0.4/tests/.libs$ export LD_LIBRARY_PATH=/home/kif/wrk/zmq/root/lib/x86_64-linux-gnu/ ; ./test_conflate ; unset LD_LIBRARY_PATH
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
sent
recieved
closed inbound
closed outbound
class destroyed
kif@nto-202:~/wrk/zmq/zeromq-4.0.4/tests/.libs$


And so on: with symlink set on libpthread-2.13.so it works too, but with libpthread-2.19p.so package built from debian repository doesn't.

mutex.hpp and test_comflate applied.

 
--
ildar.
OAO NPP "Polygon"   http://www.plgn.ru
/*
    Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    0MQ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __ZMQ_MUTEX_HPP_INCLUDED__
#define __ZMQ_MUTEX_HPP_INCLUDED__

#include "platform.hpp"
#include "err.hpp"

//  Mutex class encapsulates OS mutex in a platform-independent way.

#ifdef ZMQ_HAVE_WINDOWS

#include "windows.hpp"

namespace zmq
{

    class mutex_t
    {
    public:
        inline mutex_t ()
        {
            InitializeCriticalSection (&cs);
        }

        inline ~mutex_t ()
        {
            DeleteCriticalSection (&cs);
        }

        inline void lock ()
        {
            EnterCriticalSection (&cs);
        }

        inline bool try_lock ()
        {
            return (TryEnterCriticalSection (&cs)) ? true : false;
        }

        inline void unlock ()
        {
            LeaveCriticalSection (&cs);
        }

    private:

        CRITICAL_SECTION cs;

        //  Disable copy construction and assignment.
        mutex_t (const mutex_t&);
        void operator = (const mutex_t&);
    };

}

#else

#include <pthread.h>

namespace zmq
{

    class mutex_t
    {
    public:
        inline mutex_t ()
        {
            int rc = pthread_mutex_init (&mutex, NULL);
            posix_assert (rc);
        }

        inline ~mutex_t ()
        {
            int rc = pthread_mutex_destroy (&mutex);
		if (rc) printf("-------\npthread_mutex_destroy (&mutex) returned %d, errno: %d\n-------", rc, errno);
            posix_assert (rc);
        }

        inline void lock ()
        {
            int rc = pthread_mutex_lock (&mutex);
            posix_assert (rc);
        }

        inline bool try_lock ()
        {
            int rc = pthread_mutex_trylock (&mutex);
            if (rc == EBUSY)
                return false;

            posix_assert (rc);
            return true;
        }

        inline void unlock ()
        {
            int rc = pthread_mutex_unlock (&mutex);
            posix_assert (rc);
        }

    private:

        pthread_mutex_t mutex;

        // Disable copy construction and assignment.
        mutex_t (const mutex_t&);
        const mutex_t &operator = (const mutex_t&);
    };

}

#endif


namespace zmq
{
    struct scoped_lock_t
    {
        scoped_lock_t (mutex_t& mutex_)
            : mutex (mutex_)
        {
            mutex.lock ();
        }

        ~scoped_lock_t ()
        {
            mutex.unlock ();
        }

    private:

        mutex_t& mutex;

        // Disable copy construction and assignment.
        scoped_lock_t (const scoped_lock_t&);
        const scoped_lock_t &operator = (const scoped_lock_t&);
    };
}

#endif
/*
    Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    0MQ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "testutil.hpp"

int main (int argc, char *argv [])
{
    const char *bind_to = "tcp://127.0.0.1:5555";

    int rc;

    void* ctx = zmq_init (1);
    assert (ctx);

    void* s_in = zmq_socket (ctx, ZMQ_PULL);
    assert (s_in);

    int conflate = 1;
    rc = zmq_setsockopt (s_in, ZMQ_CONFLATE, &conflate, sizeof(conflate));
    assert (rc == 0);

    rc = zmq_bind (s_in, bind_to);
    assert (rc == 0);

    void* s_out = zmq_socket (ctx, ZMQ_PUSH);
    assert (s_out);

    rc = zmq_connect (s_out, bind_to);
    assert (rc == 0);

    int message_count = 20;
    for (int j = 0; j < message_count; ++j) {
        rc = zmq_send(s_out, (void*)&j, sizeof(int), 0);
        if (rc < 0) {
            printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno));
            return -1;
        }
puts("sent");
    }
    msleep (SETTLE_TIME);

    int payload_recved = 0;
    rc = zmq_recv (s_in, (void*)&payload_recved, sizeof(int), 0);
puts("recieved");
    assert (rc > 0);
    assert (payload_recved == message_count - 1);

    rc = zmq_close (s_in);
    assert (rc == 0);
puts("closed inbound");
    rc = zmq_close (s_out);
    assert (rc == 0);
puts("closed outbound");

    rc = zmq_term (ctx);
    assert (rc == 0);
puts("class destroyed");

    return 0;
}

Reply to: