Skip to content

fix(netconf): lock candidate on Set, recover dirty candidate, and retire poisoned sessions - #569

Draft
steiler wants to merge 3 commits into
mainfrom
fix/netconf-candidate-cleanup
Draft

steiler wants to merge 3 commits into
mainfrom
fix/netconf-candidate-cleanup

Conversation

@steiler

@steiler steiler commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Hardens candidate datastore lifecycle and cleanup in pkg/datastore/target/netconf so failed or interrupted transactions do not leave stale uncommitted changes or leaked locks on NETCONF targets:

  • Candidate lock / unlock lifecycle (nc.go): Wraps commit-datastore: candidate writes in <lock><target><candidate/></target></lock> … <unlock> (leaving running mode unlocked). Under RFC 6241 §8.3.4, holding <lock> on <candidate> also causes the server to automatically discard uncommitted changes if the session drops mid-flight, while isolating <candidate> from concurrent sessions.
  • Dirty-candidate recovery vs. active lock (types/errors.go, driver.go, scrapligo.go, nc.go): Classifies <lock> <rpc-error> replies carrying <error-info>/<session-id> (any namespace prefix, including 0 for non-NETCONF lock holders) as nctypes.ErrLockHeld, failing fast without issuing <discard-changes/>. When Lock("candidate") fails with a non-session, non-ErrLockHeld error (unlocked candidate with leftover uncommitted changes), runs <discard-changes/> once and retries Lock("candidate").
  • Poisoned-session retirement (nc.go): Ensures filterRPCErrors failures clean up <candidate>, and whenever post-edit Discard() or Unlock("candidate") fails, retires the session asynchronously and schedules a background reconnect (honoring the ErrCapabilitiesChanged cooldown when applicable) while preserving the primary Set result (err on failed edit/commit, SetDataResponse if Commit() already succeeded).

Testing

  • go test -race ./pkg/datastore/target/netconf/...
  • go test ./...

…ire poisoned sessions

Signed-off-by: Markus Vahlenkamp <markus.vahlenkamp@nokia.com>
…tests

Signed-off-by: Markus Vahlenkamp <markus.vahlenkamp@nokia.com>
…-cleanup

Signed-off-by: Markus Vahlenkamp <markus.vahlenkamp@nokia.com>

# Conflicts:
#	pkg/datastore/target/netconf/CONTEXT.md
#	pkg/datastore/target/netconf/driver/scrapligo/scrapligo.go
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.61062% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/datastore/target/netconf/nc.go 85.71% 9 Missing and 4 partials ⚠️
...store/target/netconf/driver/scrapligo/scrapligo.go 95.45% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant