-
Notifications
You must be signed in to change notification settings - Fork 35
Avoid race conditions when handling data #570
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
Conversation
Signed-off-by: Florian Lehner <[email protected]>
Signed-off-by: Florian Lehner <[email protected]>
Signed-off-by: Florian Lehner <[email protected]>
Signed-off-by: Florian Lehner <[email protected]>
Signed-off-by: Florian Lehner <[email protected]>
Signed-off-by: Florian Lehner <[email protected]>
Signed-off-by: Florian Lehner <[email protected]>
Signed-off-by: Florian Lehner <[email protected]>
Signed-off-by: Florian Lehner <[email protected]>
// with any encoding format | ||
ErrInvalidEncoding = errors.New("encoded data not supported") | ||
// ErrNoData indicates that APMData.data is empty | ||
ErrNoData = errors.New("no data") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this, no data is not an error for the batch and I don't like returning no data errors. Now that we have already handled no data case in ForwardAPMData
, can we remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is your suggestion to return for thelen(apmData.Data) == 0
case in AddAgentData()
?
Just because there is a check in ForwardAPMData()
does not prevent other users of AddAgentData()
running into this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is that for the batch having an empty data is not an error. The batch can just not add data in this case. If we want to protect against edge cases we should do it at the source (like how we do in ForwardAPMData
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if we want to be more specific in handling the behaviour, we could introduce another method in the batch to check the metadata status, something like bool HasMetadata()
and incorporate it where we require such a check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still consider the use case len(apmData.Data) == 0
in AddAgentData()
dangerous even if the only caller atm ™️ is using a check. What makes this package and its API safe to use, if something else calls AddAgentData()
?
Even if no data is considered a non error case, what should it be considered instead and how should it be treated? With the current behavior it seems to run into issues.
we could introduce another method in the batch to check the metadata status, something like bool HasMetadata() and incorporate it where we require such a check.
If AddAgentData()
implements such a check, what should be returned in a case where
- there is not metadata but
len(apmData.Data) != 0
. Is in this case data loss the expected result? - there is metadata but
len(apmData.Data) == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What makes this package and its API safe to use, if something else calls AddAgentData()?
Agent data here refers to data from the APM agents and intake-v2 is the only supported protocol. What other cases do you have in mind here?
there is not metadata but len(apmData.Data) != 0. Is in this case data loss the expected result?
If data from the agent is not nil then it MUST have the metadata as the first line.
there is metadata but len(apmData.Data) == 0
apmData.Data
is including the metadata so this is also not possible. We could have only metadata in the body and that is okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lahsivjar So essentially in your view, ErrNoData
and associated logic is redundant as "no data" can take place during normal operation, and if we want to check for this case, we should do it before calling AddAgentData
. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, yes! I don't have a strong opinion here so feel free to ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the fix that @florianl implements in this PR (not exiting the processing loop when len(data.Data) == 0
) is important and should be merged. @lahsivjar Do we need anything else to get this merged?
// with any encoding format | ||
ErrInvalidEncoding = errors.New("encoded data not supported") | ||
// ErrNoData indicates that APMData.data is empty | ||
ErrNoData = errors.New("no data") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lahsivjar So essentially in your view, ErrNoData
and associated logic is redundant as "no data" can take place during normal operation, and if we want to check for this case, we should do it before calling AddAgentData
. Is that correct?
I think with |
Signed-off-by: Florian Lehner <[email protected]>
Initialize local variable only once and make sure expected APMData is handled first.