Skip to content

script: Restrict scope of mutable borrow in IDBTransaction::ObjectStore.#40139

Merged
jdm merged 1 commit intoservo:mainfrom
jdm:object-store-hazard
Oct 25, 2025
Merged

script: Restrict scope of mutable borrow in IDBTransaction::ObjectStore.#40139
jdm merged 1 commit intoservo:mainfrom
jdm:object-store-hazard

Conversation

@jdm
Copy link
Copy Markdown
Member

@jdm jdm commented Oct 24, 2025

This avoids a borrow hazard when we create a new IDBObjectStore object and that triggers a GC.

Testing: Many IndexedDB tests no longer crash when using a debug mozjs build and full GC zeal. This configuration is not run in CI.
Fixes: #39946

@jdm jdm requested a review from gterzian as a code owner October 24, 2025 18:52
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 24, 2025
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Oct 24, 2025
@jdm jdm force-pushed the object-store-hazard branch from bf58995 to 25fdaee Compare October 25, 2025 01:00
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 25, 2025
@jdm jdm enabled auto-merge October 25, 2025 01:00
return Ok(DomRoot::from_ref(&*store));
}

Ok(DomRoot::from_ref(&*store))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this was never caught by Lint tho...
Only difference is that here we have a &mut Dom<IDBObjectStore>.

It is better to Ok(DomRoot::from_ref(store)) as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the only reason is to downcast from &mut to &, although unnecessary when passing as arg.

@jdm jdm added this pull request to the merge queue Oct 25, 2025
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 25, 2025
Merged via the queue into servo:main with commit 991ce54 Oct 25, 2025
33 checks passed
@jdm jdm deleted the object-store-hazard branch October 25, 2025 03:32
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 25, 2025
);
self.store_handles
.borrow_mut()
.insert(name.to_string(), Dom::from_ref(&*store));
Copy link
Copy Markdown
Member

@yezhizhen yezhizhen Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I am confused after #40155 (comment): what happens if store also get GCed before inserting?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. store won't be GCed because it is rooted
  2. IDBObjectStore::new can trigger GC. GC here means tracing to check what can be collected, so my previous comment certainly make no sense as it is rooted.
  3. The problem was the tracing would also try to mutably borrow the RefCell resulting in hazards.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All correct!

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

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Borrow hazard in IDBTransaction::ObjectStore

4 participants