Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development/messageunit #1714

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c33741b
[Tests/unit/core] : Fix build 'test_message_unit.cpp'
msieben May 1, 2024
3793120
[Tests/unit] : Do not depend on 'IPTestAdministrator' if not used
msieben Jun 20, 2024
1f58b65
Merge branch 'master' into development/iptestadministrator
msieben Jun 21, 2024
3eb94a9
Merge branch 'master' into development/iptestadministrator
msieben Jun 24, 2024
0674ec8
Merge branch 'master' into development/iptestadministrator
msieben Jun 24, 2024
dd920b9
Merge branch 'master' into development/iptestadministrator
MFransen69 Jun 25, 2024
c9156cb
Merge branch 'master' into development/iptestadministrator
msieben Jul 8, 2024
5e55df6
[Tests/unit/tests] : Cherry pick 'test_iptestmanager' from developmen…
msieben Jul 15, 2024
9579773
[Tests/unit / Tests/unit/tests] : Improve synchronization usage of 'I…
msieben Jul 15, 2024
8bc4c8a
[core/IPCChannel] : cherry-pick from 'development/ipcchannel_dangling…
msieben Jul 16, 2024
22e7e3b
Tests/unit/core] : align tests with '957977381dfa8137f1475131622390eb…
msieben Jul 16, 2024
346fb6e
[Tests/unit] : Improve synchronization with premature signalling
msieben Jul 22, 2024
3696efa
[Tests/unit] : Add test cases to 'Tests/unit/tests/test_iptestmanager…
msieben Jul 22, 2024
7c9a286
[Tests/unit/core] : align tests with '346fb6ec2a0da5058f7a581190e63c7…
msieben Jul 22, 2024
a7ef6b2
Merge branch 'master' into development/iptestadministrator
msieben Jul 24, 2024
3737343
[Tests/unit/core] : amend '7c9a286d1398de9f2b470b02bb58596120f0d8c9'
msieben Jul 25, 2024
3453693
Merge branch 'master' into development/messageunit
msieben Jul 25, 2024
da8760c
[Tests/core/unit] : align 'test_message_unit' with recent changes
msieben Jul 26, 2024
c84512f
[Tests/core/unit] : 'test_message_unit' does not use 'IPTestAdministr…
msieben Jul 26, 2024
9c470c7
[Tests/core/unit] : cherry pick from 'development/messageunit'
msieben Jul 26, 2024
be5e514
[Tests/unit/core] : Use 'IPTestAdministrator' for 'PopMessageShouldRe…
msieben Jul 26, 2024
5339888
Merge branch 'development/iptestadministrator' into development/messa…
msieben Jul 29, 2024
7a25695
[Tests/unit/core] : Print modules in 'test_message_unit' to support d…
msieben Jul 29, 2024
d34ded1
[Tests/unit/core] : Match 'MessageUnit::Open' with 'MessageUnit::Clos…
msieben Jul 30, 2024
da02a32
[core/TextStreamRedirectType / core/MessageUnit] : improve (return) v…
msieben Jul 30, 2024
f075681
[core/MessageUnit] : add a comment on the available modules
msieben Jul 30, 2024
5248a4b
[core/messaging/Control] : Unconditionally revoke ourself if we uncon…
msieben Aug 1, 2024
ce9ead1
[core/MessageStore] : match 'Serialize' length
msieben Aug 2, 2024
93ada9a
Revert "[core/messaging/Control] : Unconditionally revoke ourself if …
msieben Aug 5, 2024
cdc50b2
[core/MessageStore / messaging/MessageUnit] : Cleaning up is responsi…
msieben Aug 5, 2024
3e16646
[Tests/unit/IPTestAdministrator] : Cherry pick 'a9f67288fc51d43a7cc52…
msieben Aug 5, 2024
798b280
[Tests/unit/core] : fix 'test_message_unit' build and improves tests
msieben Aug 5, 2024
3329f27
Merge branch 'master' into development/messageunit
msieben Aug 5, 2024
71fec8a
[Tests/unit/core] : add 'test_message_unit' to build
msieben Aug 5, 2024
24dbdfc
Merge branch 'development/messageunit' of github.com:RDKCentral/Thund…
msieben Aug 5, 2024
90f3519
[core/MessageStore] : avoid 'variable not used' compiler warning if T…
msieben Aug 5, 2024
9154bdd
[core/TextStreamRedirectType] : Introduced variables in 'da02a3229175…
msieben Aug 6, 2024
6fc8f74
[ [core/MessageStore] : capture 'this'
msieben Aug 6, 2024
b4f620e
[Tests/unit/core] : expect modules activated in default for 'test_mes…
msieben Aug 6, 2024
a746f7b
[Tests/unit/core] : enable 'test_threadpool' and 'test_workerpool
msieben Aug 7, 2024
7c19e8f
[Tests/unit/core] : properly initialize variable for 'test_message_unit'
msieben Aug 7, 2024
aabbbbc
Merge branch 'master' into development/messageunit
msieben Aug 7, 2024
1a53ac8
Revert "[core/IPCChannel] : cherry-pick from 'development/ipcchannel_…
msieben Aug 7, 2024
8790fb8
Revert "[core/TextStreamRedirectType] : Introduced variables in 'da02…
msieben Aug 7, 2024
45c1a99
Partly revert "[core/TextStreamRedirectType / core/MessageUnit] : imp…
msieben Aug 7, 2024
3aeb751
[Tests/unit/core] : Enable 'test_message_unit'
msieben Sep 2, 2024
131da15
Merge branch 'master' into development/messageunit
msieben Sep 2, 2024
3935b0e
Merge branch 'master' into development/messageunit
msieben Sep 5, 2024
5754339
Merge branch 'master' into development/messageunit
VeithMetro Sep 11, 2024
c95399c
Merge branch 'master' into development/messageunit
msieben Sep 12, 2024
e4cdd8e
Merge branch 'master' into development/messageunit
msieben Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Source/core/MessageStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ ENUM_CONVERSION_END(Core::Messaging::Metadata::type)
{
_adminLock.Lock();

while (_controlList.size() > 0) {
VARIABLE_IS_NOT_USED auto& control = *_controlList.front();
for_each (_controlList.begin(), _controlList.end(), [this](VARIABLE_IS_NOT_USED Core::Messaging::IControl* const & control) {
TRACE_L1(_T("MessageControl %s, size = %u was not disposed before"), typeid(control).name(), static_cast<uint32_t>(_controlList.size()));
_controlList.front()->Destroy();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we dropping Destroy() here?

I tried to produce a scenario in which the _controlList was not clearly properly and this TRACE_L1 was shown, and I couldn't get to that point, but I think at least in theory it is still possible, right?

In that case, I think that the removal of Destroy() might lead to a segmentation fault as this destructor is the consequence of MessageUnit being destructed, thus messages should no longer be sent

Copy link
Contributor Author

@msieben msieben Sep 16, 2024

Choose a reason for hiding this comment

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

It actually caused a pure virtual function call fault - at the time of writing. See cdc50b2

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is a similar situation to #1714 (comment). If we destory the whole Controls class which stores all IControl objects in ControlList, then it feels necessary to notify the other side about this fact, to make sure it won't try to perform any more traces, syslogs, etc. on these controls

}
);

_adminLock.Unlock();
}
Expand Down Expand Up @@ -157,9 +156,9 @@ namespace Core {
{
uint16_t length = 0;

ASSERT(bufferSize > (sizeof(_type) + (sizeof(_category[0]) * 2)));
ASSERT(bufferSize > (sizeof(_type) + _category.size() + 1));

if (bufferSize > (sizeof(_type) + (sizeof(_category[0]) * 2))) {
if (bufferSize > (sizeof(_type) + _category.size() + 1)) {
Copy link
Contributor

@VeithMetro VeithMetro Sep 11, 2024

Choose a reason for hiding this comment

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

Correct me if I am wrong but as far as I understand, in the Deserialize() we expect the _category to be an empty string, so _category.size() returns zero, right?

Before we had (sizeof(_category[0]) * 2)), so:

  • _category[0] refers to the first character of the std::string object
  • If the string is empty, the operator[] should still return a char with the value \0 (null terminator)
  • sizeof(_category[0]) is the size of the character type (char), which is always 1 byte
  • and for some bizarre reason we were multiplying it by two, probably because we wanted to make sure the buffer holds at least one character besides a null terminator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cannot correct you because I do not know the answer. I am not the original author of the code. What I noticed was that the test failed and length in Serialize() is given by https://github.com/rdkcentral/Thunder/blob/development/messageunit/Source/core/MessageStore.cpp#L130.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, what I think is that _category.size() is not necessary here since it should always return 0 in the Deserialize() - perhaps you could check this in tests.

Instead of using it, maybe it would be better to just check if bufferSize > (sizeof(_type) + 1) if we want to potentially allow empty categories, or + 2 if we want to make sure there is at least one character..

On the other hand, perhaps it would be even better to only keep the ASSERT and remove this condition altogether @sebaszm?

Core::FrameType<0> frame(const_cast<uint8_t*>(buffer), bufferSize, bufferSize);
Core::FrameType<0>::Reader frameReader(frame, 0);
_type = frameReader.Number<type>();
Expand Down
3 changes: 2 additions & 1 deletion Source/messaging/MessageUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ namespace Thunder {
public:
void Handle(Core::Messaging::IControl* control) override
{
ASSERT(control != nullptr);

const string& module = control->Metadata().Module();
if (std::find(_modules.begin(), _modules.end(), module) == _modules.end()) {
_modules.push_back(module);
Expand Down Expand Up @@ -312,7 +314,6 @@ namespace Thunder {
Messaging::ConsoleStandardOut::Instance().Close();
}
Core::Messaging::IStore::Set(nullptr);
Core::Messaging::IControl::Iterate(handler);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it also looks like we are getting rid of a Destroy() call via iterate on all handles. Basically the whole section above with the Handler class definition and its Handle() method calling Destroy() is no longer used, why is that?

Copy link
Contributor Author

@msieben msieben Sep 16, 2024

Choose a reason for hiding this comment

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

You might recall the discussion outside the Github context about the ANNOUNCE-macros and elements initially added do not re-appear on open-close-open of MessageUnit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See cdc50b2

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, but it looks to me that if we drop this Iterate() and thus Destroy(), the other side (e.g. here) will not be aware that MessageUnit has been closed and its controls should no longer be used

Copy link
Contributor Author

@msieben msieben Sep 16, 2024

Choose a reason for hiding this comment

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

You (@VeithMetro) mentioned the use case is not what had been considered in the original design. However, from the tests it can be concluded that is a defect iff allowed. Imho allowing an explicit Close (https://github.com/rdkcentral/Thunder/blob/development/messageunit/Source/messaging/MessageUnit.h#L1007) suggests the code flow is allowed. A more recent test illustrates no current issue by re-adding the Destroy(). However, the code is not reached in any of the current tests (anymore). I suggest for now it is best to revert the removal of Destroy() and see what the future brings, or, try to implement a test which deliberately can excite that code point. What is your opinion?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think having a test which deliberately can excite that point in code, and which preferably suits a real use case would be great. Have you maybe tried to run Thunder to see if the Close() is ever executed? E.g. when closing MessageControl or other plugins which use messaging?

Copy link
Contributor Author

@msieben msieben Sep 17, 2024

Choose a reason for hiding this comment

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

Any object that derives from IControl that is passed via Announce (

static void Announce(IControl* control);
) but is never revoked (
static void Revoke(IControl* control);
) would trigger a segfault at program end (
_controlList.front()->Destroy();
) or via a call to Controls::Iterate for a handler (
void Iterate(Core::Messaging::IControl::IHandler& handler)
) calling a method on it if it already went out of scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, that's why in messaging we make sure that a control will always be Revoked() (here) thus removed from our _controlList


_adminLock.Lock();
_dispatcher.reset(nullptr);
Expand Down
2 changes: 0 additions & 2 deletions Tests/unit/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ add_executable(${TEST_RUNNER_NAME}
test_workerpool.cpp
test_xgetopt.cpp
)
#[[
target_sources(${TEST_RUNNER_NAME} PRIVATE test_message_unit.cpp)
target_link_libraries(${TEST_RUNNER_NAME}
ThunderMessaging
)
]]
else()
add_executable(${TEST_RUNNER_NAME}
test_databuffer.cpp
Expand Down
Loading