'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >
<p>I created client application. It works correctly when I am sending single messages client &lt;=> sever . But when I am sending a lot of messages for performance purposes client crashes in two different way:</p>

<pre><code>(gdb) run
Starting program: /home/x64joxer/workerGenerators/Worker2/worker -t -i 192.168.0.6 -p 6000 -d 5 -l //home/x64joxer/workerGenerators/Worker2/
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;boost::system::system_error&gt; &gt;'
  what():  set_option: Bad file descriptor
[New Thread 0x7fffe77fe700 (LWP 19310)]
[New Thread 0x7ffff4f24700 (LWP 18720)]
[New Thread 0x7fffe7fff700 (LWP 18148)]
[New Thread 0x7ffff5725700 (LWP 17582)]
[New Thread 0x7ffff5f26700 (LWP 16613)]
[New Thread 0x7ffff6727700 (LWP 16612)]

Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7ffff5f26700 (LWP 16613)]
0x00007ffff6965267 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:55
55      ../sysdeps/unix/sysv/linux/raise.c: Nie ma takiego pliku ani katalogu.
(gdb) bt
#0  0x00007ffff6965267 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:55
#1  0x00007ffff6966eca in __GI_abort () at abort.c:89
#2  0x00007ffff749706d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff7494ee6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff7494f31 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff74f0ec1 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff6d016aa in start_thread (arg=0x7ffff5f26700) at pthread_create.c:333
#7  0x00007ffff6a36eed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109





(gdb) run
Starting program: /home/x64joxer/workerGenerators/Worker4/worker -t -i 192.168.0.6 -p 6000 -d 5 -l //home/x64joxer/workerGenerators/Worker4/
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff4f24700 (LWP 17302)]
[New Thread 0x7ffff5f26700 (LWP 16583)]
[New Thread 0x7ffff6727700 (LWP 16582)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff6727700 (LWP 16582)]
0x000000000044b902 in boost::asio::detail::epoll_reactor::deregister_descriptor (this=0x6a1a10, descriptor=6, descriptor_data=@0x7fffffffe2b8: 0x6a0d20, closing=true) at /usr/include/boost/asio/detail/impl/epoll_reactor.ipp:309
309     /usr/include/boost/asio/detail/impl/epoll_reactor.ipp: Nie ma takiego pliku ani katalogu.
(gdb) by
Undefined command: "by".  Try "help".
(gdb) bt
#0  0x000000000044b902 in boost::asio::detail::epoll_reactor::deregister_descriptor (this=0x6a1a10, descriptor=6, descriptor_data=@0x7fffffffe2b8: 0x6a0d20, closing=true) at /usr/include/boost/asio/detail/impl/epoll_reactor.ipp:309
#1  0x000000000044ecc0 in boost::asio::detail::reactive_socket_service_base::close (this=0x6a11f8, impl=..., ec=...) at /usr/include/boost/asio/detail/impl/reactive_socket_service_base.ipp:104
#2  0x000000000045476e in boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt;::close (this=0x6a11d0, impl=..., ec=...) at /usr/include/boost/asio/stream_socket_service.hpp:170
#3  0x0000000000452d60 in boost::asio::basic_socket&lt;boost::asio::ip::tcp, boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt; &gt;::close (this=0x7fffffffe2b0) at /usr/include/boost/asio/basic_socket.hpp:356
#4  0x0000000000449556 in TCPSocketBody::DoClose (this=0x7fffffffe260) at TCP/TCPSocketBody.cpp:158
#5  0x000000000045afbd in boost::_mfi::mf0&lt;void, TCPSocketBody&gt;::operator() (this=0x7ffff6726be0, p=0x7fffffffe260) at /usr/include/boost/bind/mem_fn_template.hpp:49
#6  0x000000000045a77a in boost::_bi::list1&lt;boost::_bi::value&lt;TCPSocketBody*&gt; &gt;::operator()&lt;boost::_mfi::mf0&lt;void, TCPSocketBody&gt;, boost::_bi::list0&gt; (this=0x7ffff6726bf0, f=..., a=...) at /usr/include/boost/bind/bind.hpp:253
#7  0x0000000000459986 in boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, TCPSocketBody&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;TCPSocketBody*&gt; &gt; &gt;::operator() (this=0x7ffff6726be0) at /usr/include/boost/bind/bind_template.hpp:20
#8  0x0000000000458bef in boost::asio::asio_handler_invoke&lt;boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, TCPSocketBody&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;TCPSocketBody*&gt; &gt; &gt; &gt; (function=...)
    at /usr/include/boost/asio/handler_invoke_hook.hpp:69
#9  0x0000000000457b77 in boost_asio_handler_invoke_helpers::invoke&lt;boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, TCPSocketBody&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;TCPSocketBody*&gt; &gt; &gt;, boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, TCPSocketBody&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;TCPSocketBody*&gt; &gt; &gt; &gt; (function=..., context=...) at /usr/include/boost/asio/detail/handler_invoke_helpers.hpp:37
#10 0x0000000000456747 in boost::asio::detail::completion_handler&lt;boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, TCPSocketBody&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;TCPSocketBody*&gt; &gt; &gt; &gt;::do_complete (owner=0x6a1960, 
    base=0x7fffe8001c70) at /usr/include/boost/asio/detail/completion_handler.hpp:68
#11 0x000000000044a744 in boost::asio::detail::task_io_service_operation::complete (this=0x7fffe8001c70, owner=..., ec=..., bytes_transferred=0) at /usr/include/boost/asio/detail/task_io_service_operation.hpp:38
#12 0x000000000044d102 in boost::asio::detail::task_io_service::do_run_one (this=0x6a1960, lock=..., this_thread=..., ec=...) at /usr/include/boost/asio/detail/impl/task_io_service.ipp:384
#13 0x000000000044cb23 in boost::asio::detail::task_io_service::run (this=0x6a1960, ec=...) at /usr/include/boost/asio/detail/impl/task_io_service.ipp:153
#14 0x000000000044d4d4 in boost::asio::io_service::run (this=0x7fffffffe2a0) at /usr/include/boost/asio/impl/io_service.ipp:59
#15 0x000000000045c575 in boost::_mfi::mf0&lt;unsigned long, boost::asio::io_service&gt;::operator() (this=0x6a1008, p=0x7fffffffe2a0) at /usr/include/boost/bind/mem_fn_template.hpp:49
#16 0x000000000045c4bb in boost::_bi::list1&lt;boost::_bi::value&lt;boost::asio::io_service*&gt; &gt;::operator()&lt;unsigned long, boost::_mfi::mf0&lt;unsigned long, boost::asio::io_service&gt;, boost::_bi::list0&gt; (this=0x6a1018, f=..., a=...)
    at /usr/include/boost/bind/bind.hpp:243
#17 0x000000000045c2aa in boost::_bi::bind_t&lt;unsigned long, boost::_mfi::mf0&lt;unsigned long, boost::asio::io_service&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;boost::asio::io_service*&gt; &gt; &gt;::operator() (this=0x6a1008)
    at /usr/include/boost/bind/bind_template.hpp:20
#18 0x000000000045bf84 in boost::detail::thread_data&lt;boost::_bi::bind_t&lt;unsigned long, boost::_mfi::mf0&lt;unsigned long, boost::asio::io_service&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;boost::asio::io_service*&gt; &gt; &gt; &gt;::run (this=0x6a0e50)
    at /usr/include/boost/thread/detail/thread.hpp:117
#19 0x00007ffff79c809a in ?? () from /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.55.0
#20 0x00007ffff6d016aa in start_thread (arg=0x7ffff6727700) at pthread_create.c:333
#21 0x00007ffff6a36eed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
(gdb) 
</code></pre>

<p>It looks like something is crashing in boost asio socket but I am not sure what happening. I tried to put in all boost::asio commands into try block but it looks like exception appear from socket thread.
Here Is part of ma socket implementation:</p>

<pre><code>#include "TCPSocketBody.h"

TCPSocketBody::TCPSocketBody() : socket_(io_service_global),
                                 resolver(io_service_global),
                                 connected(false),
                                 expectedMessage(0)
{
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: TCPSocketBody::TCPSocketBody(const std::string &amp;adress, const std::string &amp;port)";

    data_to_read = new char[MessageCoder::MaxMessageSize()];
}

void TCPSocketBody::Close()
{
  TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: void TCPSocketBody::Close()";

  io_service_global.post(boost::bind(&amp;TCPSocketBody::DoClose, this));
}

void TCPSocketBody::Connect(const std::string &amp;adress, const std::string &amp;port)
{
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: void TCPSocketBody::Connect(const std::string &amp;adress, const std::string &amp;port)";

    io_service_global.reset();

    iterator = resolver.resolve({adress, port});

     boost::asio::async_connect(socket_, iterator,
           boost::bind(&amp;TCPSocketBody::HandleConnect, this,
           boost::asio::placeholders::error));     

     socket_.set_option(boost::asio::ip::tcp::no_delay(true));
     socket_.set_option( boost::asio::socket_base::send_buffer_size( 65536 ) );
     socket_.set_option( boost::asio::socket_base::receive_buffer_size( 65536 ) );

     boost::thread(boost::bind(&amp;boost::asio::io_service::run, &amp;io_service_global));
}

void TCPSocketBody::HandleConnect(const boost::system::error_code&amp; error)
{
  TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: void TCPSocketBody::HandleConnect(const boost::system::error_code&amp; error)";

  if (!error)
  {           
      connected = true;

      Message tempMessage;
      char *buffer = new char[MessageCoder::MaxMessageConnectedSize()];
      MessageCoder::ClearChar(buffer, MessageCoder::MaxMessageConnectedSize());
      MessageCoder::CreateConnectedMessage(buffer);
      tempMessage.CopyWsk(meWsk, buffer);
      messageQueue-&gt;PushBack(tempMessage);

      TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: Sending Connected message to queue: " &lt;&lt; buffer;

      boost::asio::async_read(socket_,
         boost::asio::buffer(data_to_read, MessageCoder::BufferSize()), boost::asio::transfer_all(),
         boost::bind(&amp;TCPSocketBody::HandleReadHeader, this,
           boost::asio::placeholders::error));

  } else
  {
        Traces() &lt;&lt; "\n" &lt;&lt; "ERR: Connection error!";
        Close();
  }
}

void TCPSocketBody::HandleReadHeader(const boost::system::error_code&amp; error)
{
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: void TCPSocketBody::HandleReadHeader(const boost::system::error_code&amp; error)";

    expectedMessage = MessageCoder::HeaderToVal(data_to_read);    

    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: Expecting message with lenn: " &lt;&lt; expectedMessage;

    if (expectedMessage &gt; MessageCoder::MaxMessageSize())
    {
       //TO_DO Traces() &lt;&lt; "\n" &lt;&lt; "ERR: Protocol error. Message too long:" &lt;&lt; std::string(data_to_read);
       //TO_DO expectedMessage = 0;
       //TO_DO Close();
        expectedMessage = 0;

        boost::asio::async_read(socket_,
           boost::asio::buffer(data_to_read, MessageCoder::BufferSize()), boost::asio::transfer_all(),
           boost::bind(&amp;TCPSocketBody::HandleReadHeader, this,
             boost::asio::placeholders::error));
    } else
    {
        boost::asio::async_read(socket_,
           boost::asio::buffer(data_to_read, expectedMessage), boost::asio::transfer_all(),
           boost::bind(&amp;TCPSocketBody::HandleReadMessage, this,
             boost::asio::placeholders::error));
    }
}

void TCPSocketBody::HandleReadMessage(const boost::system::error_code&amp; error)
{
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: void TCPSocketBody::HandleReadMessage(const boost::system::error_code&amp; error)";

    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: Message received: " &lt;&lt; std::string(data_to_read);

    Message tempMessage;
    tempMessage.CopyData(meWsk, data_to_read);
    messageQueue-&gt;PushBack(tempMessage);
    expectedMessage = 0;        

    boost::asio::async_read(socket_,
       boost::asio::buffer(data_to_read, MessageCoder::BufferSize()), boost::asio::transfer_all(),
       boost::bind(&amp;TCPSocketBody::HandleReadHeader, this,
         boost::asio::placeholders::error));
}

void TCPSocketBody::WriteMessage(char *dataToSend)
{
    io_service_global.post(boost::bind(&amp;TCPSocketBody::Write, this, dataToSend));
}

void TCPSocketBody::Write(char *dataToSend)
{
    TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: void TCPSocketBody::Write(char *dataToSend)";

    writeMutex.lock();
    data = dataToSend;

    boost::asio::async_write(socket_,
        boost::asio::buffer(data, std::strlen(data)),
        boost::bind(&amp;TCPSocketBody::HandleWrite, this,
          boost::asio::placeholders::error));

}

void TCPSocketBody::HandleWrite(const boost::system::error_code&amp; error)
{
  TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: void TCPSocketBody::HandleWrite(const boost::system::error_code&amp; error)";

  writeMutex.unlock();

  if (!error)
  {

      /*boost::asio::async_write(socket_,
          boost::asio::buffer(data,
            std::strlen(data)),
          boost::bind(&amp;TCPSocketBody::HandleWrite, this,
            boost::asio::placeholders::error));*/
  }
  else
  {
        Traces() &lt;&lt; "\n" &lt;&lt; "ERR: Write error!";
        Close();
  }
}

void TCPSocketBody::DoClose()
{
  TRACE_FLAG_FOR_CLASS_TCPSocketBody Traces() &lt;&lt; "\n" &lt;&lt; "LOG: void TCPSocketBody::DoClose()";

  socket_.close();  
  connected = false;
  Message tempMessage;
  char *buffer = new char[MessageCoder::MaxMessageConnectionCloseSize()];
  MessageCoder::ClearChar(buffer, MessageCoder::MaxMessageConnectionCloseSize());
  MessageCoder::CreateCloseConnectionMessage(buffer);
  tempMessage.CopyWsk(meWsk, buffer);
  messageQueue-&gt;PushBack(tempMessage);  

}

TCPSocketBody::~TCPSocketBody()
{
    delete [] data_to_read;
}
</code></pre>

<p>I will be grateful for any help.</p>