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

Bug/3162 registration destroys compound values #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

kzangeli
Copy link

@kzangeli kzangeli commented May 9, 2018

Fixed issue telefonicaid#3162 ... I think ...
The only real change is that in ContextAttribute::ContextAttribute(ContextAttribute* caP, bool useDefaultType) the compound is cloned and not "set to point to the same pointer".
I encountered some really important problems with leaks and when implementing help code to understand the leak, the leak ... disappeared ... :(
I have no explanation for this except that ... the current implementation works, with the vector of cloned compounds that later isn't used for anything at all, it just changes the timing.
So, the leak was a timing problem, not new to us ...
However, if the problem comes back, this new vector will be useful.

In lack of a real fix, this "workaround" solves the problem, at least temporarily ...

@@ -52,6 +52,79 @@ using namespace orion;



typedef struct CompoundSave
Copy link
Collaborator

Choose a reason for hiding this comment

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

If at the end we go with the workaround implemented by this PR, an explanation of the workaround should be included in a comment in the code in order to guide for a definitive solution. The text in the PR body is a good starting point for that.

Issue telefonicaid#3162 would remain open until the definitive solution comes.

std::string state;
} CompoundSave;

static CompoundSave compoundSaveV[100];
Copy link
Collaborator

Choose a reason for hiding this comment

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

100 should be unhardwired to a #define (maybe in this same file, no need to include it in global.h in the case of a workaround)

csP->aParentP = aParentP;
csP->state = "used";

++compoundSaveIx;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about if this index overpass 100 ?

{
if (aP->compoundValueP == compoundSaveV[ix].compoundP)
{
if (compoundSaveV[ix].state == "used")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Style:

if ()
{
}

(Pls review the PR, I have seen more of this in other places)

csP->name = aP->name;
csP->compoundP = aP->compoundValueP;
csP->aParentP = aParentP;
csP->state = "used";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe an enum (instead of plain strings) should be used for states.

@@ -569,6 +569,8 @@ static void requestCompleted
std::string spath = (ciP->servicePathV.size() > 0)? ciP->servicePathV[0] : "";
struct timespec reqEndTime;

// compoundSaveReport();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this comment is preserved at the end (seems to be a good idea), a FIXME mark citing telefonicaid#3162 should be included in the line above it.

@@ -0,0 +1,368 @@

Copy link
Collaborator

Choose a reason for hiding this comment

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

Blank line could be removed.

@@ -23,15 +23,13 @@
#
Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand this test was already include as "issue bug demostration" and the present PR is enabling it (and fixing some parts, I guess)

Copy link
Collaborator

Choose a reason for hiding this comment

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

In fact... appart from "format changes" (e.g. echo, content-length adjust, JSON pretty print, etc.) is there any real change in the PR?

Copy link
Author

Choose a reason for hiding this comment

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

The real change is that instead of just copying the compound pointer in ContextAttribute::ContextAttribute(ContextAttribute* caP, bool useDefaultType),
the compound is cloned.

Copy link
Author

Choose a reason for hiding this comment

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

This change gave leaks that were ... really hard to understand.
My guess: timing.
To understand the leaks I saved a pointer of all compounds cloned right there in "the real change", and on free I remove those pointers, to finally free those that were still in the vector.

[ I just remembered this ] Imagine my surprise when finding that there were no compounds left to free.

However, if I remove the saving-compound-pointers-to-vector, then I get memory leaks.
So, the vector is "unneeded code" that is essential due to the timing it changes. Without it, we get memory leaks.

And now you know why I don't like this fix ...

It works, but more time for investigation is needed. Doesn't have to be right now. Especially not as this fix is needed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ups... I didn't make myself clear enough. I mean, not the changes in the PR in general, but the changes of the .test in the PR, i.e.:

In fact... appart from "format changes" (e.g. echo, content-length adjust, JSON pretty print, etc.) is there any real change in this .test?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(The explanation about the PR itself is good... but I'll move to the general comment in the PR to continue discussion)

#
# 01. Create entity E1 without attributes
# 02. Append new geo:box attribute (attr3) -> OK
#
Copy link
Collaborator

Choose a reason for hiding this comment

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

A step 03 with GET to check that the attributes has been really appended should be included.

Copy link
Author

@kzangeli kzangeli Jun 7, 2018

Choose a reason for hiding this comment

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

Need to take a look at this test to understand what has happened.
The way it is ... makes no sense whatsoever.

The idea behind step 2 is to actually find the entity (entities without attr that have a registration weren't found).
A recent PR of mine fixes this.
But, I found that bug myself implementing the fix of this PR.

I don't care about the new entity after Append. Only that the append works (i.e., the entity was found)

Copy link
Author

Choose a reason for hiding this comment

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

Si, I looked into this a little ...
This test I used simply to provoke the bug fixed in telefonicaid#3193.
its current contents is what remains after tests, with the registration removed.
The bug is fixed, and has its own test. This test is no longer needed and will be removed.

@@ -0,0 +1,82 @@
# Copyright 2016 Telefonica Investigacion y Desarrollo, S.A.U
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is under directory 3162_context_providers_legacy_non_primitive/ but it seem is has nothing to do with CP... maybe should be moved to another directory? Maybe is already covered (maybe grep for "geo:box" could help)?

Copy link
Author

Choose a reason for hiding this comment

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

The test is called registration_without_provider.test ...

But, what happened to the registration? It's gone.
I guess I was experimenting and forgot to revert it.

Once t he registration is back, you will see the connection to CPs.

@fgalan
Copy link
Collaborator

fgalan commented Jun 8, 2018

@kzangeli said:

The real change is that instead of just copying the compound pointer in ContextAttribute::ContextAttribute(ContextAttribute* caP, bool useDefaultType),
the compound is cloned.

This change gave leaks that were ... really hard to understand.
My guess: timing.
To understand the leaks I saved a pointer of all compounds cloned right there in "the real change", and on free I remove those pointers, to finally free those that were still in the vector.

[ I just remembered this ] Imagine my surprise when finding that there were no compounds left to free.

However, if I remove the saving-compound-pointers-to-vector, then I get memory leaks.
So, the vector is "unneeded code" that is essential due to the timing it changes. Without it, we get memory leaks.

And now you know why I don't like this fix ...

It works, but more time for investigation is needed. Doesn't have to be right now. Especially not as this fix is needed.

@fgalan
Copy link
Collaborator

fgalan commented Jun 8, 2018

However, if I remove the saving-compound-pointers-to-vector, then I get memory leaks.
So, the vector is "unneeded code" that is essential due to the timing it changes. Without it, we get memory leaks.

So your theory is that the saving-compound-pointers-to-vector introduce some time delay that avoid the leaks?

@kzangeli
Copy link
Author

kzangeli commented Jun 8, 2018 via email

@fgalan
Copy link
Collaborator

fgalan commented Jun 8, 2018

In that case, why don't just replace the saving-compound-pointers-to-vector with a sleep() statement? It would require some tunning to find the right value, but it would be much more simpler and easy to adjust (as a "gauge" if the delay needs to be adjusted later).

@kzangeli
Copy link
Author

kzangeli commented Jun 8, 2018 via email

@jason-fox
Copy link

jason-fox commented Jun 28, 2018

@kzangeli @fgalan - I've just built this branch locally, and I can confirm that the changes do indeed work and will fix the issue. I'm surprised that so few users are using compound entities within their context data and that no-one else has come across the issue.

For example, if I am a GPS unit, I should be storing by data a GeoJSON point right? Therefore GPS units should be producing compound values.

@fgalan
Copy link
Collaborator

fgalan commented Jun 28, 2018

For example, if I am a GPS unit, I should be storing by data a GeoJSON point right? Therefore GPS units should be producing compound values.

Not necessarily... GeoJSON point can be represented using geo:point attribute type with value e.g. "40.23,-3.23" which is a string.

@fgalan
Copy link
Collaborator

fgalan commented Jun 28, 2018

Thanks for the feedback @jason-fox ! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants