You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Manipulating an XMLElement randomly breaks (observed in flaky tests). It is possible that the manipulation isn't done properly on the Ruby side or that we have some memory mapping issues between Ruby and Rust.
Examples
Failures:
1) Y::XMLElement when changing commits automatically
Failure/Error: expect(changes[0].first[:added].map(&:tag)).to match_array(%w[A B C])
expected collection contained: ["A", "B", "C"]
actual collection contained: ["\u0000", "A", "C"]
the missing elements were: ["B"]
the extra elements were: ["\u0000"]
# ./spec/y/yxml_element_spec.rb:324:in `block (3 levels) in <top (required)>'
Failures:
1) Y::XMLElement when changing commits automatically
Failure/Error: expect(changes[0].first[:added].map(&:tag)).to match_array(%w[A B C])
expected collection contained: ["A", "B", "C"]
actual collection contained: ["\n", "A", "C"]
the missing elements were: ["B"]
the extra elements were: ["\n"]
# ./spec/y/xml_element_spec.rb:324:in `block (3 levels) in <top (required)>'
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /Users/hannesmoser/.cargo/registry/src/github.com-1ecc6299db9ec823/yrs-0.12.0/src/types/xml.rs:110:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal: called `Option::unwrap()` on a `None` value 0) Y::XMLElement when changing commits automatically Failure/Error: yxml_element_tag fatal: called `Option::unwrap()` on a `None` value# ./lib/y/xml.rb:237:in `yxml_element_tag'# ./lib/y/xml.rb:237:in `tag'# ./spec/y/xml_element_spec.rb:320:in `map'# ./spec/y/xml_element_spec.rb:320:in `block (3 levels) in <top (required)>'
Analysis
For whatever reason, some of the (XML) elements that are forwarded to Ruby are no longer in memory when we access them. The container is there Y::XMLElement, but when accessing the tag, we get a different set of errors.
When I add GC.start after the observer is attached, I can reliably produce the issues. I think this confirms that the elements emitted by change events are no longer accessible due to being garbage collected.
# garbage collect immediately
GC.start
There is some documentation about this in magnus. We are required to keep values on the stack, and I think it is impossible, because if we delete an element, it actually gets removed from the CRDT, and we just pass it to the callback and eventually access it later on. In other words, in order for the observer pattern to work, I need to control garbage collection 🤷. https://github.com/matsadler/magnus#safety
The text was updated successfully, but these errors were encountered:
Problem
Manipulating an
XMLElement
randomly breaks (observed in flaky tests). It is possible that the manipulation isn't done properly on the Ruby side or that we have some memory mapping issues between Ruby and Rust.Examples
Job: https://github.com/y-crdt/yrb/actions/runs/3234322746/jobs/5297285225
Job: https://github.com/y-crdt/yrb/actions/runs/3287990605/jobs/5417793161
Analysis
For whatever reason, some of the (XML) elements that are forwarded to Ruby are no longer in memory when we access them. The container is there
Y::XMLElement
, but when accessing thetag
, we get a different set of errors.When I add
GC.start
after the observer is attached, I can reliably produce the issues. I think this confirms that the elements emitted by change events are no longer accessible due to being garbage collected.There is some documentation about this in
magnus
. We are required to keep values on the stack, and I think it is impossible, because if we delete an element, it actually gets removed from the CRDT, and we just pass it to the callback and eventually access it later on. In other words, in order for the observer pattern to work, I need to control garbage collection 🤷.https://github.com/matsadler/magnus#safety
The text was updated successfully, but these errors were encountered: