Repository navigation
Description
Describe the bug:
Servo crashes when editing or removing a tag in the DevTools inspector.
This comes from script/dom/element.rs::remove_first_matching_attribute, which calls script/dom/mutationobserver.rs::queue_a_mutation_record. The problematic check is in the first line:
if !target.global().as_window().get_exists_mut_observer() {
return;
}This calls an unsafe function down the stack, which ends up crashing the program. It calls the GetCurrentRealmOrNull from mozjs. The last call seems to be to JSContext::realm().
If this check is removed the crash goes away and everything seems to work, but I imagine that it is there for a reason and that there is a problem with how the node was constructed, it might be missing some information. But I may be a bit outside my depth here since I don't have that much experience with mozjs or realms.
To Reproduce:
- Launch Servo with the DevTools server enabled:
./mach run --devtools=1234 - In Firefox, go to
about:debuggingand connect tolocalhost:1234(or the port number you specified) - Click inspect on one of the tabs, and go to the inspector tab
- Edit one of the tag attributes (for example, change
<p style="color:red;">to<p style="color:blue;">) - Servo crashes
Platform:
Linux 6.10 (NixOS 24.05), happening on main (29a4cca).
Crash log
assertion failed: !GetCurrentRealmOrNull(*cx).is_null() (thread Script(1,1), at components/script/realms.rs:24)
0: servoshell::backtrace::print
at /persist/home/eri/Code/servo/ports/servoshell/backtrace.rs:18:5
1: servoshell::panic_hook::panic_hook
at /persist/home/eri/Code/servo/ports/servoshell/panic_hook.rs:38:17
2: core::ops::function::Fn::call
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/ops/function.rs:79:5
3: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2034:9
std::panicking::rust_panic_with_hook
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:783:13
4: std::panicking::begin_panic_handler::{{closure}}
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:649:13
5: std::sys_common::backtrace::__rust_end_short_backtrace
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:171:18
6: rust_begin_unwind
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5
7: core::panicking::panic_fmt
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:72:14
8: core::panicking::panic
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:145:5
9: script::realms::AlreadyInRealm::assert_for_cx
at /persist/home/eri/Code/servo/components/script/realms.rs:24:13
10: script::dom::bindings::reflector::DomObject::global
at /persist/home/eri/Code/servo/components/script/dom/bindings/reflector.rs:103:21
11: script::dom::mutationobserver::MutationObserver::queue_a_mutation_record
at /persist/home/eri/Code/servo/components/script/dom/mutationobserver.rs:136:13
12: script::dom::element::Element::remove_first_matching_attribute::{{closure}}
at /persist/home/eri/Code/servo/components/script/dom/element.rs:1628:13
13: core::option::Option<T>::map
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:1073:29
14: script::dom::element::Element::remove_first_matching_attribute
at /persist/home/eri/Code/servo/components/script/dom/element.rs:1615:9
15: script::dom::element::Element::remove_attribute_by_name
at /persist/home/eri/Code/servo/components/script/dom/element.rs:1607:9
16: <script::dom::element::Element as script::dom::bindings::codegen::Bindings::ElementBinding::Element_Binding::ElementMethods>::RemoveAttribute
at /persist/home/eri/Code/servo/components/script/dom/element.rs:2282:9
17: script::devtools::handle_modify_attribute
at /persist/home/eri/Code/servo/components/script/devtools.rs:223:21
18: script::script_thread::ScriptThread::handle_msg_from_devtools
at /persist/home/eri/Code/servo/components/script/script_thread.rs:2518:17
19: script::script_thread::ScriptThread::handle_msgs::{{closure}}
at /persist/home/eri/Code/servo/components/script/script_thread.rs:1959:48
20: script::script_thread::ScriptThread::profile_event
at /persist/home/eri/Code/servo/components/script/script_thread.rs:2214:13
21: script::script_thread::ScriptThread::handle_msgs
at /persist/home/eri/Code/servo/components/script/script_thread.rs:1951:26
22: script::script_thread::ScriptThread::start
at /persist/home/eri/Code/servo/components/script/script_thread.rs:1454:15
23: <script::script_thread::ScriptThread as script_layout_interface::ScriptThreadFactory>::create::{{closure}}::{{closure}}
at /persist/home/eri/Code/servo/components/script/script_thread.rs:845:25
24: profile_traits::mem::ProfilerChan::run_with_memory_reporting
at /persist/home/eri/Code/servo/components/shared/profile/mem.rs:91:9
25: <script::script_thread::ScriptThread as script_layout_interface::ScriptThreadFactory>::create::{{closure}}
at /persist/home/eri/Code/servo/components/script/script_thread.rs:843:17
26: std::sys_common::backtrace::__rust_begin_short_backtrace
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:155:18
27: std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/thread/mod.rs:528:17
28: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panic/unwind_safe.rs:272:9
29: std::panicking::try::do_call
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:552:40
30: __rust_try
31: std::panicking::try
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:516:19
32: std::panic::catch_unwind
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panic.rs:146:14
std::thread::Builder::spawn_unchecked_::{{closure}}
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/thread/mod.rs:527:30
33: core::ops::function::FnOnce::call_once{{vtable.shim}}
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/ops/function.rs:250:5
34: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020:9
<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020:9
std::sys::pal::unix::thread::Thread::new::thread_start
at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys/pal/unix/thread.rs:108:17
35: start_thread
36: __GI___clone3
Activity
mrobinson commentedon Jul 30, 2024
Where is the entry point from DevTools into the
scriptcode? Perhaps we just need to make sure to enter a realm before making any modifications to the DOM?eerii commentedon Jul 30, 2024
I think it is
handle_msg_from_devtoolsfromscript/script_tread, which calls the functions inscript/devtools. The messages are sent from each of the devtools actors using anIpcSender.gterzian commentedon Jul 30, 2024
Sounds like it.
Example:
servo/components/script/script_thread.rs
Line 1555 in e23dc0b
eerii commentedon Jul 30, 2024
That was it! I added this to
handle_modify_attributeand it no longer crashes. It makes sense since we are modifying the DOM. I'm going to fix the DevTools reply and I'll open a PR.