Skip to content

Commit af269c1

Browse files
author
yuanjie
committed
fix: properly clean tcp channel resources on perform_listen_operation thread exit
Signed-off-by: yuanjie <a1574944154@gmail.com> Signed-off-by: yuanjie <s-yuanjie@kernelsoft.com>
1 parent aba95a5 commit af269c1

1 file changed

Lines changed: 44 additions & 15 deletions

File tree

src/cpp/rtps/transport/TCPTransportInterface.cpp

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,30 +190,22 @@ void TCPTransportInterface::clean()
190190

191191
{
192192
std::vector<std::shared_ptr<TCPChannelResource>> channels;
193-
std::vector<eprosima::fastdds::rtps::Locator> delete_channels;
194-
195193
{
196194
std::unique_lock<std::mutex> scopedLock(sockets_map_mutex_);
197195
std::unique_lock<std::mutex> unbound_lock(unbound_map_mutex_);
198196

199-
channels = unbound_channel_resources_;
197+
channels = std::move(unbound_channel_resources_);
200198

201199
for (auto& channel : channel_resources_)
202200
{
203201
if (std::find(channels.begin(), channels.end(), channel.second) == channels.end())
204202
{
205203
channels.push_back(channel.second);
206204
}
207-
else
208-
{
209-
delete_channels.push_back(channel.first);
210-
}
205+
211206
}
212-
}
213207

214-
for (auto& delete_channel : delete_channels)
215-
{
216-
channel_resources_.erase(delete_channel);
208+
channel_resources_.clear();
217209
}
218210

219211
for (auto& channel : channels)
@@ -1175,10 +1167,6 @@ void TCPTransportInterface::perform_listen_operation(
11751167
channel->change_status(TCPChannelResource::eConnectionStatus::eWaitingForBind);
11761168
}
11771169
}
1178-
1179-
std::unique_lock<std::mutex> lock(rtcp_message_manager_mutex_);
1180-
rtcp_message_manager.reset();
1181-
rtcp_message_manager_cv_.notify_one();
11821170
}
11831171
else
11841172
{
@@ -1220,6 +1208,47 @@ void TCPTransportInterface::perform_listen_operation(
12201208
}
12211209
}
12221210

1211+
if (channel)
1212+
{
1213+
std::vector<eprosima::fastdds::rtps::Locator> delete_channels;
1214+
bool channel_found = false;
1215+
1216+
{
1217+
std::unique_lock<std::mutex> scopedLock(sockets_map_mutex_);
1218+
std::unique_lock<std::mutex> unbound_lock(unbound_map_mutex_);
1219+
1220+
for (auto& channel_resource : channel_resources_)
1221+
{
1222+
if (channel_resource.second == channel)
1223+
{
1224+
delete_channels.push_back(channel_resource.first);
1225+
channel_found = true;
1226+
}
1227+
}
1228+
1229+
for (auto& delete_channel : delete_channels)
1230+
{
1231+
channel_resources_.erase(delete_channel);
1232+
}
1233+
1234+
auto it_channel = std::find(unbound_channel_resources_.begin(), unbound_channel_resources_.end(), channel);
1235+
if (it_channel != unbound_channel_resources_.end())
1236+
{
1237+
unbound_channel_resources_.erase(it_channel);
1238+
channel_found = true;
1239+
}
1240+
}
1241+
1242+
if (channel_found)
1243+
{
1244+
channel->clear();
1245+
}
1246+
}
1247+
1248+
std::unique_lock<std::mutex> lock(rtcp_message_manager_mutex_);
1249+
rtcp_message_manager.reset();
1250+
rtcp_message_manager_cv_.notify_one();
1251+
12231252
EPROSIMA_LOG_INFO(RTCP, "End PerformListenOperation " << channel->locator());
12241253
}
12251254

0 commit comments

Comments
 (0)