@@ -1536,14 +1536,19 @@ namespace aws { namespace iot { namespace securedtunneling {
15361536 BOOST_LOG_SEV (log, trace) << " Put data " << data_to_send->size () << " bytes into the web_socket_outgoing_message_queue for service id: " << service_id;
15371537 tcp_connection::pointer socket_connection = get_tcp_connection (tac, service_id);
15381538 data_message temp = std::make_pair (data_to_send, socket_connection->after_send_message );
1539+
1540+ const std::lock_guard<std::mutex> lock (tac.web_socket_outgoing_message_queue_mutex );
15391541 tac.web_socket_outgoing_message_queue .push (temp);
15401542 // Are we already writing?
15411543 if (tac.web_socket_outgoing_message_queue .size () > 1 )
1544+ {
15421545 return ;
1546+ }
15431547 }
15441548
15451549 // We are not currently writing, so send this immediately
15461550 data_message message_to_send = tac.web_socket_outgoing_message_queue .front ();
1551+
15471552 tac.wss ->async_write (message_to_send.first ->data (), [=, &tac](boost::system::error_code const &ec, std::size_t const bytes_sent)
15481553 {
15491554 if (ec)
@@ -1552,12 +1557,14 @@ namespace aws { namespace iot { namespace securedtunneling {
15521557 }
15531558 BOOST_LOG_SEV (log, trace) << " Sent " << bytes_sent << " bytes over websocket for service id: " << service_id;
15541559 std::function<void ()> capture_after_send_message = message_to_send.second ;
1555- tac.web_socket_outgoing_message_queue .pop ();
15561560
15571561 if (capture_after_send_message)
15581562 {
15591563 capture_after_send_message ();
15601564 }
1565+
1566+ const std::lock_guard<std::mutex> lock (tac.web_socket_outgoing_message_queue_mutex );
1567+ tac.web_socket_outgoing_message_queue .pop ();
15611568 if (tac.web_socket_outgoing_message_queue .empty ())
15621569 {
15631570 BOOST_LOG_SEV (log, trace) << " web_socket_outgoing_message_queue is empty, no more messages to send." ;
0 commit comments