Reference Layer RwLock Conflicts #354
Replies: 4 comments 1 reply
-
|
Here are some options that ChatGPT thinks we should consider 😁: Option 1 — Precompute keys before locking the source holon (recommended)Idea: Separate “compute keys” from “mutate relationships” so we don’t call Sketch:
Pros:
Cons:
Option 2 — Special-case self-edges in the existing add pathIdea: Detect when the target is the same holon as the source and avoid calling Sketch:
Pros:
Cons:
Option 3 — Skip
|
Beta Was this translation helpful? Give feedback.
-
|
Thanks for sleuthing this out and surfacing your findings as a Discussion @owleyeview ! This uncovers some important design considerations. Of the options ChatGPT suggested, two and three are non-starters due to lost functionality. Option 1 is viable and 4 is perhaps not as risky as advertised given that we recently moved lock acquisition responsibility inside the implementation of the reference layer, instead of leaving it with callers on the reference layer. So we have clear line of sight to the scope of any given operation and never hold locks outside the scope of any single operation. This helps! That said, I think the simplest and most effective fix is to just reduce lock granularity for Note that we don't actually need a write lock on the holon when adding/removing related holons from one of the relationships in its relationship map.
...and locking the collection (not the source holon) when adding references. So Recommendation: Option 5Change the implementation of |
Beta Was this translation helpful? Give feedback.
-
|
Ah... I'd forgotten that Option 5 would have to change the definitions of StagedRelationshipMap and TransientRelationshipMap to something like this: Then we'd do a 2-step locking protocol for add_related_holons (for both staged and transient holons). But the structural change to the two relationship maps has a pretty large ripple effect on both Even worse, the change to interior mutability will require a change to the WritableHolon trait for add_related_holons and remove_related_holons. This trait is key part of the public API, so the ripple effect of this is unacceptably large to tackle in Issue #333. RecommendationI agree the best path forward is Option 1. |
Beta Was this translation helpful? Give feedback.
-
UpdateOption 1 (Precomputing keys before acquiring the lock and then passing them down the api chain) has been implemented.
Edit: I also created issue #355 to remind us to come back to this at some point. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've chased down some unnoticed panic cases in the reference layer:
Summary of Panic Cause in Loader Tests
I’ve traced the panics to a re-entrant
RwLockaccess that occurs whenever a single holon is both the source and target of a relationship (e.g.,TypeDescriptor DescribedBy TypeDescriptor).What’s happening
StagedReference and TransientReference both implement
add_related_holonsandremove_related_holonsby:Rc<RwLock<Holon>>), thenInside the relationship logic,
HolonCollection::{add_references, remove_references}runs.These functions maintain the collection’s key index by calling:
key(context)callskey_impl, which must:rc_holon.read()).If the relationship is a self-edge (source == target), then:
RwLock.Rust’s standard
RwLockis not re-entrant → this results in a panic.In WASM this surfaces as a
RuntimeError: unreachable, which Holochain wraps and the Sweetest test harness then unwraps → panic.Impact
How should we address this?
Beta Was this translation helpful? Give feedback.
All reactions