Skip to content

[24549] Remove stale tcp channels#6421

Open
cferreiragonz wants to merge 4 commits into
masterfrom
remove_stale_tcp_channels
Open

[24549] Remove stale tcp channels#6421
cferreiragonz wants to merge 4 commits into
masterfrom
remove_stale_tcp_channels

Conversation

@cferreiragonz
Copy link
Copy Markdown
Contributor

Description

This PR introduces logic to remove stale TCP ACCEPT type channels when the listening operation ends (Asio detects and closes the socket). We can only perform this action on ACCEPT type channels because the re-connection mechanism of the CONNECT type channels rely on detecting stale channels and try to re-establish the connection when data needs to be sent.

@Mergifyio backport 3.2.x 2.14.x

Contributor Checklist

  • Commit messages follow the project guidelines.
  • The code follows the style guidelines of this project.
  • Tests that thoroughly check the new feature have been added/Regression tests checking the bug and its fix have been added; the added tests pass locally
  • N/A: Any new/modified methods have been properly documented using Doxygen.
  • N/A: Any new configuration API has an equivalent XML API (with the corresponding XSD extension)
  • Changes are backport compatible: they do NOT break ABI nor change library core behavior.
  • Changes are API compatible.
  • N/A: New feature has been added to the versions.md file (if applicable).
  • N/A: New feature has been documented/Current behavior is correctly described in the documentation.
  • Applicable backports have been included in the description.

Reviewer Checklist

  • The PR has a milestone assigned.
  • The title and description correctly express the PR's purpose.
  • Check contributor checklist is correct.
  • If this is a critical bug fix, backports to the critical-only supported branches have been requested.
  • Check CI results: changes do not issue any warning.
  • Check CI results: failing tests are unrelated with the changes.

…lients

Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com>
Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com>
@cferreiragonz cferreiragonz added this to the v3.6.2 milestone Jun 4, 2026
@cferreiragonz cferreiragonz requested a review from Danipiza June 4, 2026 13:46
@github-actions github-actions Bot added the ci-pending PR which CI is running label Jun 4, 2026
@cferreiragonz cferreiragonz changed the title Remove stale tcp channels [24549] Remove stale tcp channels Jun 4, 2026
Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com>
@cferreiragonz cferreiragonz requested review from richiprosima and removed request for richiprosima June 5, 2026 07:36
@cferreiragonz cferreiragonz linked an issue Jun 5, 2026 that may be closed by this pull request
1 task
Comment thread test/unittest/transport/TCPv4Tests.cpp Outdated

// Wait for the server to finish the BindConnectionRequest handshake
auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5);
while (server.get_channel_resources().empty() &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Possible data race. We can use in MockTCPv4Transport.h

size_t get_channel_resources_size() const
{
    std::lock_guard<std::mutex> lock(unbound_map_mutex_);
    return unbound_channel_resources_.size();
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
EXPECT_TRUE(server.get_channel_resources().empty());
EXPECT_TRUE(server.get_unbound_channel_resources().empty());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here

size_t get_unbound_channel_resources_size() const
{
    std::lock_guard<std::mutex> lock(unbound_map_mutex_);
    return unbound_channel_resources_.size();
}

Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com>
@cferreiragonz cferreiragonz requested a review from Danipiza June 5, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-pending PR which CI is running

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in TCPChannelResource

2 participants