@@ -535,9 +535,12 @@ typedef boost::lockfree::queue<message_wrapper_t*, boost::lockfree::fixed_sized<
535535 continue ;
536536
537537#define ERASE_AND_CONTINUE (IT,CONTAINER ) \
538- IT=CONTAINER.erase(IT); \
539- --connection_count; \
540- continue ;
538+ { \
539+ std::lock_guard lock (connections_lock); \
540+ IT=CONTAINER.erase (IT); \
541+ --connection_count; \
542+ continue ; \
543+ }
541544
542545class Manager {
543546public:
@@ -886,12 +889,14 @@ class Manager {
886889 }
887890 // if error occurred during creation the creation will be retried in the main thread
888891 ++connection_count;
889- auto conn = connections.emplace (tmp_id, std::make_unique<connection_t >(cct, info, verify_ssl, ca_location)).first ->second .get ();
890- ldout (cct, 10 ) << " AMQP connect: new connection is created. Total connections: " << connection_count << dendl;
891- if (!new_state (conn, tmp_id)) {
892- ldout (cct, 1 ) << " AMQP connect: new connection '" << to_string (tmp_id) << " ' is created. but state creation failed (will retry). error: " <<
893- status_to_string (conn->status ) << " (" << conn->reply_code << " )" << dendl;
892+ auto conn = std::make_unique<connection_t >(cct, info, verify_ssl, ca_location);
893+ if (new_state (conn.get (), tmp_id)) {
894+ ldout (cct, 10 ) << " AMQP connect: new connection is created. Total connections: " << connection_count << dendl;
895+ } else {
896+ ldout (cct, 1 ) << " AMQP connect: new connection '" << to_string (tmp_id) << " ' is created. but state creation failed (will retry). error: " <<
897+ status_to_string (conn->status ) << " (" << conn->reply_code << " )" << dendl;
894898 }
899+ connections.emplace (tmp_id, std::move (conn));
895900 id = std::move (tmp_id);
896901 return true ;
897902 }
0 commit comments