Hello,

Concerning this point, i still have the same crash even after modifying the
code to be thread safe.
I attached the corrected code.

If i add a sleep of 50 ms before stopping the container everything works
correctly.

I think there is a concurrency problem somewhere in the proton code. Do you
confirm?

Best regards,
Rabih

On Wed, Mar 27, 2019 at 5:31 PM Rabih M <[email protected]> wrote:

> Hello,
>
> I am using proton cpp version 0.27.0.
> I have a random crash when calling stop on the container after closing the
> connection.
> Please find the attached the code and the stack.
>
> In the doc, it is said that the container object is thread safe but
> apparently there is flaw...
>
> Can you please advise?
>
> Do you need me to create a Jira issue?
>
>
> Best regards,
>
> Rabih
>
#include <proton/connection.hpp>
#include <proton/container.hpp>
#include <proton/messaging_handler.hpp>

#include <iostream>
#include <thread>

class handler : public proton::messaging_handler {

public:
   handler(const std::string& u) : m_url(u) {}

   proton::connection m_con;
   std::promise<void> m_startProm;
   std::promise<void> m_closeProm;

private:
   void on_connection_open(proton::connection& c)override{
       m_con = c;
       m_startProm.set_value();
   }
   void on_transport_close(proton::transport&)override {
      m_closeProm.set_value();
   }

   std::string m_url;
};


int main () {
{
   try {
      std::string url("//127.0.0.1:5672");
      handler h(url);
      proton::container c(h);
      c.auto_stop(false);
      std::thread clientThread([&]() {
         try
         {
            c.run();
         }
         catch (const std::exception& e) {
            std::cerr << "Broker threw exception: " << e.what() << std::endl;
         }});

      c.connect(url);
      h.m_startProm.get_future().get();
      h.m_con.work_queue().add([&]() { h.m_con.close(); });
      h.m_closeProm.get_future().get();
      c.stop();
      if (clientThread.joinable()) {
         clientThread.join();
      }
   }
   catch (std::exception& e) {
      std::cerr << e.what() << std::endl;
   }
   return 0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to