Skip to content

Bugfix cm send loop - #288

Open
mlohvynenko wants to merge 2 commits into
aosedge:developfrom
mlohvynenko:bugfix_cm_send_loop
Open

Bugfix cm send loop#288
mlohvynenko wants to merge 2 commits into
aosedge:developfrom
mlohvynenko:bugfix_cm_send_loop

Conversation

@mlohvynenko

Copy link
Copy Markdown
Member

No description provided.

When sending a message, if the send operation fails, trigger
a disconnect event to start the reconnection process.
Otherwise, sending loop might send messages to a closed socket
consuming CPU resources and causing a high CPU usage
in a short period of time.

Signed-off-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com>
This patch wraps exception as error in close connection, so
subscribers will be notified about the connection closure even
if web socket shutdown raises an exception.

Signed-off-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com>
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses reconnect behavior in the CM communication layer when sends fail during a disconnect/reconnect cycle, and adds a regression test to cover the scenario. It also adjusts shutdown/disconnect handling to ensure subscribers are notified of disconnect events even when graceful shutdown throws.

Changes:

  • Add a new ReconnectOnSendFailure test that drives concurrent send-queue activity during disconnect/reconnect.
  • Update connection teardown to always notify disconnect subscribers even if WebSocket::shutdown() throws, and return the shutdown error.
  • Attempt to trigger disconnect from the send-queue thread on Poco::Net::NetException.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/cm/communication/tests/communication.cpp Adds regression test to reproduce send/reconnect contention scenario.
src/cm/communication/communication.cpp Adjusts disconnect/close behavior and adds disconnect-on-send-failure handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +913 to +918
} catch (const Poco::Net::NetException& e) {
LOG_ERR() << "Failed to send message" << Log::Field(common::utils::ToAosError(e));

if (auto err = Disconnect(); !err.IsNone()) {
LOG_ERR() << "Failed to disconnect from cloud web socket server" << Log::Field(err);
}
}
});

ASSERT_EQ(firstMessageSent.get_future().wait_for(std::chrono::seconds(5)), std::future_status::ready);

@mykola-kobets-epam mykola-kobets-epam left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Mykola Kobets <mykola_kobets@epam.com>

@al1img al1img left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants