From 49bd3116ae0d81c9eb5feeedb78a00832d5d001b Mon Sep 17 00:00:00 2001 From: Ignacio Montesino Date: Tue, 17 Nov 2020 14:55:12 +0100 Subject: [PATCH 1/4] Add Checks for node creation in shutdown context and context shutdown with active nodes Signed-off-by: Ignacio Montesino --- rmw_fastrtps_cpp/src/rmw_init.cpp | 4 ++++ rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp | 4 ++++ rmw_fastrtps_shared_cpp/src/rmw_node.cpp | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/rmw_fastrtps_cpp/src/rmw_init.cpp b/rmw_fastrtps_cpp/src/rmw_init.cpp index d02258c4c..91ececbe8 100644 --- a/rmw_fastrtps_cpp/src/rmw_init.cpp +++ b/rmw_fastrtps_cpp/src/rmw_init.cpp @@ -134,6 +134,10 @@ rmw_shutdown(rmw_context_t * context) context->implementation_identifier, eprosima_fastrtps_identifier, return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); + if (context->impl->count > 0) { + RMW_SET_ERROR_MSG("Shutting down context with active nodes"); + return RMW_RET_ERROR; + } context->impl->is_shutdown = true; return RMW_RET_OK; } diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp index f1f932644..b17502fab 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp @@ -134,6 +134,10 @@ rmw_shutdown(rmw_context_t * context) context->implementation_identifier, eprosima_fastrtps_identifier, return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); + if (context->impl->count > 0) { + RMW_SET_ERROR_MSG("Shutting down context with active nodes"); + return RMW_RET_ERROR; + } context->impl->is_shutdown = true; return RMW_RET_OK; } diff --git a/rmw_fastrtps_shared_cpp/src/rmw_node.cpp b/rmw_fastrtps_shared_cpp/src/rmw_node.cpp index e6d56efa3..a483eccdb 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_node.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_node.cpp @@ -68,6 +68,10 @@ __rmw_create_node( RMW_SET_ERROR_MSG_WITH_FORMAT_STRING("invalid node namespace: %s", reason); return nullptr; } + if (context->impl->is_shutdown) { + RMW_SET_ERROR_MSG("Trying to create node in a shutdown context"); + return nullptr; + } auto common_context = static_cast(context->impl->common); rmw_dds_common::GraphCache & graph_cache = common_context->graph_cache; From 3f456fca345c3a6c8e5fdc18be6529fa17d71904 Mon Sep 17 00:00:00 2001 From: Ignacio Montesino Date: Thu, 19 Nov 2020 09:07:04 +0100 Subject: [PATCH 2/4] Moved node check to rmw_context_fini Signed-off-by: Ignacio Montesino --- rmw_fastrtps_cpp/src/rmw_init.cpp | 8 ++++---- rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_init.cpp b/rmw_fastrtps_cpp/src/rmw_init.cpp index 91ececbe8..e852c9b23 100644 --- a/rmw_fastrtps_cpp/src/rmw_init.cpp +++ b/rmw_fastrtps_cpp/src/rmw_init.cpp @@ -134,10 +134,6 @@ rmw_shutdown(rmw_context_t * context) context->implementation_identifier, eprosima_fastrtps_identifier, return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); - if (context->impl->count > 0) { - RMW_SET_ERROR_MSG("Shutting down context with active nodes"); - return RMW_RET_ERROR; - } context->impl->is_shutdown = true; return RMW_RET_OK; } @@ -159,6 +155,10 @@ rmw_context_fini(rmw_context_t * context) RCUTILS_SET_ERROR_MSG("context has not been shutdown"); return RMW_RET_INVALID_ARGUMENT; } + if (context->impl->count > 0) { + RMW_SET_ERROR_MSG("Deleting a context with active nodes"); + return RMW_RET_ERROR; + } rmw_ret_t ret = rmw_init_options_fini(&context->options); delete context->impl; *context = rmw_get_zero_initialized_context(); diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp index b17502fab..40d5c051c 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp @@ -134,10 +134,6 @@ rmw_shutdown(rmw_context_t * context) context->implementation_identifier, eprosima_fastrtps_identifier, return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); - if (context->impl->count > 0) { - RMW_SET_ERROR_MSG("Shutting down context with active nodes"); - return RMW_RET_ERROR; - } context->impl->is_shutdown = true; return RMW_RET_OK; } @@ -159,6 +155,10 @@ rmw_context_fini(rmw_context_t * context) RCUTILS_SET_ERROR_MSG("context has not been shutdown"); return RMW_RET_INVALID_ARGUMENT; } + if (context->impl->count > 0) { + RMW_SET_ERROR_MSG("Deleting a context with active nodes"); + return RMW_RET_ERROR; + } rmw_ret_t ret = rmw_init_options_fini(&context->options); delete context->impl; *context = rmw_get_zero_initialized_context(); From 2d9de2f8d4d89b90e21fa861e99cf002d31f2bca Mon Sep 17 00:00:00 2001 From: Ignacio Montesino Date: Thu, 19 Nov 2020 09:08:52 +0100 Subject: [PATCH 3/4] Check already exists in rmw_create_node Signed-off-by: Ignacio Montesino --- rmw_fastrtps_shared_cpp/src/rmw_node.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/rmw_node.cpp b/rmw_fastrtps_shared_cpp/src/rmw_node.cpp index a483eccdb..e6d56efa3 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_node.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_node.cpp @@ -68,10 +68,6 @@ __rmw_create_node( RMW_SET_ERROR_MSG_WITH_FORMAT_STRING("invalid node namespace: %s", reason); return nullptr; } - if (context->impl->is_shutdown) { - RMW_SET_ERROR_MSG("Trying to create node in a shutdown context"); - return nullptr; - } auto common_context = static_cast(context->impl->common); rmw_dds_common::GraphCache & graph_cache = common_context->graph_cache; From 3bce043d2adcc5934326f409a4a83c6742d2c264 Mon Sep 17 00:00:00 2001 From: Ignacio Montesino Date: Mon, 30 Nov 2020 15:48:47 +0100 Subject: [PATCH 4/4] Applied suggested changes Signed-off-by: Ignacio Montesino --- rmw_fastrtps_cpp/src/rmw_init.cpp | 2 +- rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_init.cpp b/rmw_fastrtps_cpp/src/rmw_init.cpp index e852c9b23..4e729acf1 100644 --- a/rmw_fastrtps_cpp/src/rmw_init.cpp +++ b/rmw_fastrtps_cpp/src/rmw_init.cpp @@ -156,7 +156,7 @@ rmw_context_fini(rmw_context_t * context) return RMW_RET_INVALID_ARGUMENT; } if (context->impl->count > 0) { - RMW_SET_ERROR_MSG("Deleting a context with active nodes"); + RMW_SET_ERROR_MSG("Finalizing a context with active nodes"); return RMW_RET_ERROR; } rmw_ret_t ret = rmw_init_options_fini(&context->options); diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp index 40d5c051c..af621b2dc 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_init.cpp @@ -156,7 +156,7 @@ rmw_context_fini(rmw_context_t * context) return RMW_RET_INVALID_ARGUMENT; } if (context->impl->count > 0) { - RMW_SET_ERROR_MSG("Deleting a context with active nodes"); + RMW_SET_ERROR_MSG("Finalizing a context with active nodes"); return RMW_RET_ERROR; } rmw_ret_t ret = rmw_init_options_fini(&context->options);