Skip to content

Commit 10aa651

Browse files
committed
fix potential throwing at destructor of gateways
1 parent 00651a2 commit 10aa651

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/common/ipc/client_router.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ class ClientRouterImpl final : public ClientRouter
145145
{
146146
::syslog(LOG_DEBUG, "~Gateway(tag=%zu, seq=%zu).", endpoint_.getTag(), next_sequence_); // NOLINT
147147

148-
// `next_sequence_ == 0` means that this gateway was never used for sending messages,
149-
// and so remote router never knew about it (its tag) - no need to post "ChEnd" event.
150-
router_.onGatewayDisposal(endpoint_, next_sequence_ > 0);
148+
performWithoutThrowing([this] {
149+
//
150+
// `next_sequence_ == 0` means that this gateway was never used for sending messages,
151+
// and so remote router never knew about it (its tag) - no need to post "ChEnd" event.
152+
router_.onGatewayDisposal(endpoint_, next_sequence_ > 0);
153+
});
151154
}
152155

153156
// detail::Gateway

src/common/ipc/ipc_types.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <cerrno>
1212
#include <cstdint>
13+
#include <sys/syslog.h>
1314

1415
namespace ocvsmd
1516
{
@@ -33,6 +34,23 @@ enum class ErrorCode : int // NOLINT
3334
using Payload = cetl::span<const std::uint8_t>;
3435
using Payloads = cetl::span<const Payload>;
3536

37+
template <typename Action>
38+
void performWithoutThrowing(Action&& action) noexcept
39+
{
40+
#if defined(__cpp_exceptions)
41+
try
42+
#endif
43+
{
44+
std::forward<Action>(action)();
45+
}
46+
#if defined(__cpp_exceptions)
47+
catch (...)
48+
{
49+
::syslog(LOG_WARNING, "Unexpected exception is caught!"); // NOLINT
50+
}
51+
#endif
52+
}
53+
3654
} // namespace ipc
3755
} // namespace common
3856
} // namespace ocvsmd

src/common/ipc/server_router.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ class ServerRouterImpl final : public ServerRouter
149149
{
150150
::syslog(LOG_DEBUG, "~Gateway(cl=%zu, tag=%zu).", endpoint_.getClientId(), endpoint_.getTag()); // NOLINT
151151

152-
router_.onGatewayDisposal(endpoint_);
152+
performWithoutThrowing([this] {
153+
//
154+
router_.onGatewayDisposal(endpoint_);
155+
});
153156
}
154157

155158
// detail::Gateway

0 commit comments

Comments
 (0)