Skip to content

fix(kvs): stop GetExisting and SplitCompositeKey from panicking - #1944

Merged
SaidAltury-ibm merged 2 commits into
hyperledger-labs:mainfrom
mbrandenburger:worktree-fix-kvs-getexisting-nil-iterator
Sep 30, 2026
Merged

SaidAltury-ibm merged 2 commits into
hyperledger-labs:mainfrom
mbrandenburger:worktree-fix-kvs-getexisting-nil-iterator

Conversation

@mbrandenburger

Copy link
Copy Markdown
Member

KVS.GetExisting kept 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 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; the rest 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 "". It now returns an error for keys that lack the composite key namespace prefix or have no components.

Tests: a table test drives GetExisting through 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. TestSplitCompositeKey gains four malformed-key cases.

The iterator returned by GetByPartialCompositeID has the same pattern (store errors read as end of scan, Next dereferences a nil item). Fixing it needs an API decision, so it is tracked in a separate issue.

Fixes #1456

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Hey @mbrandenburger 👋 thanks for the PR!
I'm your friendly PR Helper Bot 🤖 and I'll be riding shotgun on this one, keeping track of your PR's status to help you get it approved and merged.

This comment updates automatically as you push changes -- think of it as your PR's live scoreboard!
Here's the latest:


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:

  • 54d1c12 fix(kvs): stop GetExisting and SplitCompositeKey from panicking

You'll need to sign your commits with GPG (e.g. git commit -S). See the Signing Guide for a step-by-step walkthrough.


✅ 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!

@github-actions github-actions Bot added the status: needs revision The pull request requires changes from the author before it can be reviewed or merged label Sep 29, 2026
@mbrandenburger mbrandenburger added this to the 26Q3 milestone Sep 29, 2026
@mbrandenburger mbrandenburger added status: needs review The pull request is ready for maintainer review and removed status: needs revision The pull request requires changes from the author before it can be reviewed or merged labels Sep 29, 2026
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>
@SaidAltury-ibm
SaidAltury-ibm force-pushed the worktree-fix-kvs-getexisting-nil-iterator branch from 47d9bc7 to 54d1c12 Compare September 29, 2026 22:21
@github-actions github-actions Bot added status: needs revision The pull request requires changes from the author before it can be reviewed or merged and removed status: needs review The pull request is ready for maintainer review labels Sep 29, 2026

@SaidAltury-ibm SaidAltury-ibm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thank you @mbrandenburger i have left a comment tell me WYT?

@SaidAltury-ibm
SaidAltury-ibm self-requested a review September 30, 2026 07:41
@mergify

mergify Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

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.

@SaidAltury-ibm
SaidAltury-ibm merged commit 4143f1b into hyperledger-labs:main Sep 30, 2026
5 checks passed
@mbrandenburger
mbrandenburger deleted the worktree-fix-kvs-getexisting-nil-iterator branch September 30, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs revision The pull request requires changes from the author before it can be reviewed or merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kvs.GetExisting panics (nil-pointer dereference) when storage iterator returns (nil, error)

2 participants