PersistentRooted<GCHashSet> does not work in ShellContext

RESOLVED FIXED in Firefox 67

Status

()

enhancement
P3
normal
RESOLVED FIXED
5 months ago
3 months ago

People

(Reporter: sfink, Assigned: sfink)

Tracking

unspecified
mozilla67
Points:
---

Firefox Tracking Flags

(firefox67 fixed)

Details

Attachments

(1 attachment, 1 obsolete attachment)

Assignee

Description

5 months ago
arai attempted to use PersistentRooted<GCHashSet> and got a !Empty() assertion during shutdown.
Assignee

Comment 1

5 months ago
The problem seems to be that we don't actually delete the main ShellContext. (We do delete worker ones).

This is not the minimal necessary change, I don't think -- when tracing through, it seemed wrong to be deleting the runtime before the context, so I swapped the order, then fixed up everything that broke.

If that causes too many issues, I can undo that part.
Attachment #9034520 - Flags: review?(jcoppeard)
Comment on attachment 9034520 [details] [diff] [review]
Fix shell context shutdown ordering

Review of attachment 9034520 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/shell/js.cpp
@@ +11102,5 @@
>    DestructSharedObjectMailbox();
>  
>    CancelOffThreadJobsForRuntime(cx);
>  
> +  JS_SetContextPrivate(cx, nullptr);

Do we not need to do this in the worker case?

::: js/src/threading/ProtectedData.cpp
@@ +55,2 @@
>    JSContext* cx = TlsContext.get();
> +  MOZ_ASSERT_IF(cx, CurrentThreadCanAccessRuntime(cx->runtime()));

Does this allow the check to pass if this is called on an unrelated (non-SM) thread?  That seems bad.
Assignee

Comment 3

5 months ago
Clearing out the context's private data isn't really necessary anywhere, it just felt dangerous to be running a bunch of code during shutdown with a dangling pointer. But you're right, I should clear it consistently. Fixed.

I switched to using AutoNoteSingleThreadedRegion to suppress the checks, and it appears to shut down successfully.

Do you have an opinion on whether a cx or rt should be shut down first, btw? Because if I didn't change that, then this patch would be simpler. Maybe it's just because my head is still stuck in a multiple-cx world that it seems wrong to me to blow away the runtime first and have a period where there is a cx without an rt. An rt without a cx didn't seem as bad.
Attachment #9034825 - Flags: review?(jcoppeard)
Assignee

Updated

5 months ago
Attachment #9034520 - Attachment is obsolete: true
Attachment #9034520 - Flags: review?(jcoppeard)
Comment on attachment 9034825 [details] [diff] [review]
Fix shell context shutdown ordering

Review of attachment 9034825 [details] [diff] [review]:
-----------------------------------------------------------------

Ah, I see.

I agree, it feels like we should destroy the context before the runtime.
Attachment #9034825 - Flags: review?(jcoppeard) → review+
Priority: -- → P3

Comment 5

3 months ago
Pushed by sfink@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/fdd74f1bbff3
Fix shell context shutdown ordering, r=jonco

Comment 6

3 months ago
bugherder
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67
You need to log in before you can comment on or make changes to this bug.