Skip to content

Commit d0b1d33

Browse files
committed
[#24061] Fixed missing dependency types
Signed-off-by: danipiza <dpizarrogallego@gmail.com>
1 parent 0d2c954 commit d0b1d33

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

ddspipe_participants/include/ddspipe_participants/types/dds/TopicDataType.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class TopicDataType : public fastdds::dds::TopicDataType
108108
//! Lazily created dynamic type used to compute key from serialized payload.
109109
mutable fastdds::dds::DynamicType::_ref_type dynamic_type_{};
110110
mutable std::mutex dynamic_type_mtx_;
111+
//! Set to true if dynamic type initialization permanently failed (missing dependencies)
112+
mutable bool dynamic_type_init_failed_{false};
111113

112114
DDSPIPE_PARTICIPANTS_DllAPI
113115
bool initialize_dynamic_type_() const;

ddspipe_participants/src/cpp/types/dds/TopicDataType.cpp

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <fastcdr/Cdr.h>
2121
#include <fastdds/dds/xtypes/dynamic_types/DynamicPubSubType.hpp>
2222
#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilderFactory.hpp>
23+
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>
2324

2425
#include <ddspipe_participants/types/dds/TopicDataType.hpp>
2526

@@ -48,6 +49,17 @@ TopicDataType::TopicDataType(
4849

4950
// Set Type Identifiers
5051
type_identifiers_ = type_identifiers;
52+
53+
// Eagerly try to build the dynamic type for keyed topics
54+
// If it fails (e.g. dependency types missing from registry), disable key computation
55+
// so the DataWriter does not drop data on the first write attempt
56+
if (keyed_ && !initialize_dynamic_type_())
57+
{
58+
EPROSIMA_LOG_WARNING(DDSPIPE_DDS_TYPESUPPORT,
59+
"Cannot build dynamic type for keyed topic " << type_name_
60+
<< ". Key computation will be disabled for this topic.");
61+
is_compute_key_provided = false;
62+
}
5163
}
5264

5365
TopicDataType::~TopicDataType()
@@ -116,8 +128,12 @@ bool TopicDataType::compute_key(
116128

117129
if (!initialize_dynamic_type_())
118130
{
131+
// Dynamic type could not be built (missing dependency types in registry)
132+
// Disable key computation so data is not dropped and future writes skip this path
119133
EPROSIMA_LOG_WARNING(DDSPIPE_DDS_TYPESUPPORT,
120-
"Failed to initialize dynamic type to compute key for " << type_name_ << ".");
134+
"Cannot compute key for type " << type_name_
135+
<< ": dynamic type unavailable. Disabling key computation.");
136+
is_compute_key_provided = false;
121137
return false;
122138
}
123139

@@ -166,12 +182,27 @@ bool TopicDataType::initialize_dynamic_type_() const
166182
return true;
167183
}
168184

185+
if (dynamic_type_init_failed_)
186+
{
187+
return false;
188+
}
189+
169190
std::lock_guard<std::mutex> lock(dynamic_type_mtx_);
191+
192+
// Handles the race where two threads both pas the first check,
193+
// then one acquires the lock and sets dynamic_type_init_failed_ = true
194+
// Without this second check, the other thread would proceed to retry initialization
195+
// after the first thread already determined its a permanent failure
170196
if (dynamic_type_)
171197
{
172198
return true;
173199
}
174200

201+
if (dynamic_type_init_failed_)
202+
{
203+
return false;
204+
}
205+
175206
fastdds::dds::xtypes::TypeInformation type_information;
176207

177208
auto& registry = fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry();
@@ -193,6 +224,7 @@ bool TopicDataType::initialize_dynamic_type_() const
193224

194225
if (!try_get_type_information(minimal_only))
195226
{
227+
dynamic_type_init_failed_ = true;
196228
return false;
197229
}
198230
}
@@ -202,17 +234,39 @@ bool TopicDataType::initialize_dynamic_type_() const
202234
fastdds::dds::xtypes::TypeObject type_object;
203235
if (fastdds::dds::RETCODE_OK != registry.get_type_object(complete_type_identifier, type_object))
204236
{
237+
dynamic_type_init_failed_ = true;
238+
return false;
239+
}
240+
241+
// Pre-check consistency before calling create_type_w_type_object
242+
// If dependencies are missing from the registry, skip type creation entirely
243+
// to avoid noisy error logs from internal FastDDS type creation functions
244+
try
245+
{
246+
fastdds::dds::xtypes::TypeObjectUtils::type_object_consistency(type_object);
247+
}
248+
catch (const fastdds::dds::xtypes::InvalidArgumentError&)
249+
{
250+
EPROSIMA_LOG_WARNING(DDSPIPE_DDS_TYPESUPPORT,
251+
"TypeObject for " << type_name_ << " has unresolvable dependencies. "
252+
<< "Skipping dynamic type creation.");
253+
dynamic_type_init_failed_ = true;
205254
return false;
206255
}
207256

208257
auto dyn_type_builder = fastdds::dds::DynamicTypeBuilderFactory::get_instance()->create_type_w_type_object(
209258
type_object);
210259
if (!dyn_type_builder)
211260
{
261+
dynamic_type_init_failed_ = true;
212262
return false;
213263
}
214264

215265
dynamic_type_ = dyn_type_builder->build();
266+
if (!dynamic_type_)
267+
{
268+
dynamic_type_init_failed_ = true;
269+
}
216270
return dynamic_type_ != nullptr;
217271
}
218272

0 commit comments

Comments
 (0)