Concurrent AVP encoding issue - AvpDataException: Not enough data in buffer! (fixes #1) #2
+293
−84
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all,
We have found 2 concurrency issues with AVP encoding/decoding when doing load tests.
And also a BufferOverflow in the end:
Problem - encoded/decoded Diameter packets get corrupted (missing child AVPs).
Reason - This is due to the fact that the function getGrouped that converts AvpImpl.java rawData to groupedData is called
concurrently
when doing encodeAvpSet(). If this is done in the loop before data.write(raw) operation in encodeAvpSet, then all child AVPs could be left unencoded (not written) to the packet (since avp.getRaw().length becomes 0). And since a correct AVP length is written here, the packet gets corrupted.2.We also obtained a
NullpointerException
in SessionImpl.java, when doing a release, due to the fact that container concurrently was set tonull
via setContainer, so this was also fixed. However, don't know what the "// FIXME" is for, but I guess it relates to the same problem.With this pull I propose a possible fix for this issue. Also to encapsulate more the existing data in AvpImpl.java, i.e. make rawData/groupedData not accessible from outside. ALSO to forbid to swap between rawData/groupedData in runtime, i.e. to not change created AVP.