layout: Prevent DomRefCell::borrow from being used in layout code#42976
Conversation
…ng thread state. Signed-off-by: Josh Matthews <[email protected]>
Signed-off-by: Josh Matthews <[email protected]>
|
I recommend reading this PR with whitespace changes turned off. |
|
We could catch problems like #42963 as well by introducing a similar DomCell type. |
| fn implemented_pseudo_element(&self) -> Option<PseudoElement> { | ||
| self.unsafe_get().implemented_pseudo_element() | ||
| unsafe { | ||
| self.unsafe_get() |
There was a problem hiding this comment.
Unrelated to this PR, but why is unsafe_get a safe function?
There was a problem hiding this comment.
I don't have a good answer for why the unsafe is in the name instead of in the type system. I think we could potentially rename it to something more clear, but it's meant to represent that it should only be called by code that is implementing the LayoutWhateverHelpers traits, since it exposes methods that could be unsafe to call in layout's worker threads.
Signed-off-by: Josh Matthews <[email protected]>
|
@simonwuelker Do you have a preference for merging this change or #42991 first? |
|
Let's merge this one first. |
|
Womp womp! servo/components/script/dom/element.rs Lines 1540 to 1541 in 45f1bdb servo/components/script/dom/element.rs Lines 352 to 354 in 45f1bdb |
servo/components/script/dom/element.rs Lines 5110 to 5112 in 45f1bdb We need to call self.each_custom_state_for_layout from that code instead.
|
|
🔨 Triggering try run (#22654988697) for Linux (WPT) |
|
|
|
🔨 Triggering try run (#22655281627) for Linux (WPT) |
|
Test results for linux-wpt from try job (#22655281627): Flaky unexpected result (30)
Stable unexpected results that are known to be intermittent (19)
Stable unexpected results (1)
|
|
|
Signed-off-by: Josh Matthews <[email protected]>
DomRefCell::borrow inside of layout code is risky because it leads to memory races if the code is ever called from layout worker threads. This can be caught via TSAN, but we can also catch it deterministically in CI by using our existing thread state debug assertions correctly.
Testing: Existing WPT test coverage is sufficient.
Fixes: #42962