Repository navigation
fix(kvs): stop GetExisting and SplitCompositeKey from panicking - #1944
Conversation
|
Hey @mbrandenburger 👋 thanks for the PR! This comment updates automatically as you push changes -- think of it as your PR's live scoreboard! PR Checks✅ DCO Sign-off -- All commits have valid sign-offs. Nice work! ❌ GPG Signature -- Heads up! The following commits don't have a verified GPG signature:
You'll need to sign your commits with GPG (e.g. ✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing! ✅ Issue Link -- Linked to #1456 (assigned to you). ⏳ All checks must pass before this PR can be reviewed. You've got this! |
GetExisting kept reading from the store iterator while the iterator returned an error, and dereferenced the returned item to evict its key from the cache. An iterator that returns a nil item with an error, as the iterators.Iterator contract allows, crashed the process. The iterator was also never closed. GetExisting now stops at the first error, returns the ids found so far, and closes the iterator. Ids read before the error stay cached, and the remaining ids are queried again on the next call. Godoc on GetExisting and Exists describes this best-effort behavior. SplitCompositeKey panicked with a slice bounds error on any key without a component separator, such as an empty string. It now returns an error for keys that do not start with the composite key namespace or have no components. Fixes hyperledger-labs#1456 Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
47d9bc7 to
54d1c12
Compare
SaidAltury-ibm
left a comment
There was a problem hiding this comment.
thank you @mbrandenburger i have left a comment tell me WYT?
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
KVS.GetExistingkept reading from the store iterator while it returned an error, and dereferenced the returned item to evict its key from the cache. An iterator that returns a nil item with an error, which theiterators.Iteratorcontract allows, crashed the process. The iterator was also never closed.GetExistingnow stops at the first error, returns the ids found so far, and closes the iterator. Ids read before the error stay cached; the rest are queried again on the next call.GetExistingandExistsdescribes this best-effort behavior.SplitCompositeKeypanicked with a slice bounds error on any key without a component separator, such as"". It now returns an error for keys that lack the composite key namespace prefix or have no components.Tests: a table test drives
GetExistingthrough a clean scan, a nil item with an error, a non-nil item with an error, and an error after some items. Each case checks the result, that iteration stops at the error, that the iterator is closed, and which ids are fetched again.TestSplitCompositeKeygains four malformed-key cases.The iterator returned by
GetByPartialCompositeIDhas the same pattern (store errors read as end of scan,Nextdereferences a nil item). Fixing it needs an API decision, so it is tracked in a separate issue.Fixes #1456