Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hubble/container: Properly deal with nil values in RingReader
When the ring-buffer is not full, we must treat nil values the same as reads outside of the readable indices. This commit ensures that `read` treats nil values the same way `readFrom` does. This has an impact on the RingReader, as we should not try to either increase or decrease the index if the current value is unreadable. If the current index is unreadable, then we have either read past the last written value, or we have tried to access an index which has already been overwritten. This commit therefore adds an error return type to `RingReader.{Next,Prev}` in order to determine which of the two cases occured. Most notably, `Next` may now return ErrInvalidData. This means this means that the value it tried to access just got overwritten by the writer from behind. In such cases we want to return an error, as otherwise `RingReader.Next` would silently stop reading and subsequentially terminate the request as if it had reached most recent value in the ring buffer (which it has not). The error is also added to `Previous`, however in that case we only ever expect ErrInvalidData, as it traverses the ring buffer in the opposite direction of the writer. The check for concurrent writes is currently missing from `readFrom`, which can suffer from the same problem. This will be added in a follow-up PR. Fixes: cilium/hubble#131 Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
- Loading branch information
Showing
5 changed files
with
164 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.