Closed Bug 1540170 Opened 6 years ago Closed 6 years ago

Ensure history service isn't initialized before we have a profile

Categories

(Toolkit :: Places, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: Gijs, Assigned: Gijs)

References

Details

Attachments

(2 files)

Split off from bug 1538968 because there are some blockers for this.

Marco, I'd like to land this but I'm a bit stuck because test_sanitizer.js creates elements (as part of parsing the HTML) that trip the DOM registervisit blah blah blah listeners. Which try to then init history.

Unfortunately, on Windows debug builds, some of the time, because the DOM code delays doing so, it can happen when we're in the middle of shutdown, and this assert https://searchfox.org/mozilla-central/rev/44a212460990ffffecf50a8e972d3cbde2e7216b/toolkit/components/places/Database.cpp#484-493 fails because we've already run the profile-change-teardown shutdown phase:

17:50:35 INFO - PID 15268 | JavaScript error: resource://gre/modules/AsyncShutdown.jsm, line 674: Error: Phase "profile-change-teardown" is finished, it is too late to register completion condition "Places Clients shutdown"

Without creating a profile in that test (which I do in the current version of the commit adding the assert), we hit the assert I'm trying to add in this test, because we attempt to create the history service when there is no profile (which will mean that places is broken, which this xpcshell test really doesn't particularly care about).

I'm not sure what best to do about this, because although xpcshell might not care, we should probably not be hitting these assertions in Database.cpp on shutdown (though admittedly they're debug only) for other places consumers in "normal" firefox runs. On the other hand, in those cases I'd expect the DB instances (and the history service) to have been instantiated sooner. I tried to make the history service's singleton getter return nullptr when we're shutting down ( https://hg.mozilla.org/try/rev/0a8232c1c8de54af23306bf98c514292d45cd30c#l2.79 ) but that doesn't seem to be sufficient, presumably I need to detect the profile-change-teardown thing separately, but I'm not sure how to do so...

Flags: needinfo?(mak77)

Let me see if I got this correctly:
Some tests run without a profile, but expect to use profile things (like history), so you are adding a profile to those tests... But now history may be initialized in the shutdown path, after the xpcshell test harness has fired the profile shutdown notification.
My gut answer would be that the test is wrong, it should actually do everything before the test is complete. Obviously that's not a trivial answer you can implement in a minute if the number of tests is large or if there isn't a clear "complete" event you could wait for.
This is a long standing problem, services initing when shutdown is already ongoing. I wonder if we could use nsIAppStartup.shuttingDown to detect this case and bail out of the service constructor?

Flags: needinfo?(mak77)

(In reply to Marco Bonardo [::mak] from comment #6)

Let me see if I got this correctly:
Some tests run without a profile, but expect to use profile things (like history), so you are adding a profile to those tests... But now history may be initialized in the shutdown path, after the xpcshell test harness has fired the profile shutdown notification.
My gut answer would be that the test is wrong, it should actually do everything before the test is complete. Obviously that's not a trivial answer you can implement in a minute if the number of tests is large or if there isn't a clear "complete" event you could wait for.
This is a long standing problem, services initing when shutdown is already ongoing. I wonder if we could use nsIAppStartup.shuttingDown to detect this case and bail out of the service constructor?

I tried this in the trypush in my previous comment, but it didn't seem to be enough. https://hg.mozilla.org/try/rev/0a8232c1c8de54af23306bf98c514292d45cd30c#l2.75 . I'm guessing profile-change-teardown happens before that shuttingDown flag is set...

we may need another flag then, maybe profileShuttingDown.

Priority: -- → P3

(In reply to :Gijs (he/him) from comment #7)

(In reply to Marco Bonardo [::mak] from comment #6)

Let me see if I got this correctly:
Some tests run without a profile, but expect to use profile things (like history), so you are adding a profile to those tests... But now history may be initialized in the shutdown path, after the xpcshell test harness has fired the profile shutdown notification.
My gut answer would be that the test is wrong, it should actually do everything before the test is complete. Obviously that's not a trivial answer you can implement in a minute if the number of tests is large or if there isn't a clear "complete" event you could wait for.
This is a long standing problem, services initing when shutdown is already ongoing. I wonder if we could use nsIAppStartup.shuttingDown to detect this case and bail out of the service constructor?

I tried this in the trypush in my previous comment, but it didn't seem to be enough. https://hg.mozilla.org/try/rev/0a8232c1c8de54af23306bf98c514292d45cd30c#l2.75 . I'm guessing profile-change-teardown happens before that shuttingDown flag is set...

OK, so xpcshell tests are the weirdest.

They manually fire all the shutdown notifications to convince things to shut down ( https://searchfox.org/mozilla-central/rev/9ee63566281365f26e7a4b06c9d4e2219e64c3e8/testing/xpcshell/head.js#608-617 ) . But of course, that doesn't change nsIAppStartup.

This explains why the extra check against nsIAppStartup when creating the history service wasn't helpful.

I believe this means we can't hit this case in practice as it is, so I just hacked up the test to deal with this by forcing us to initialize the history service while the profile (and everybody's concept of xpcom shutdown state) is sane.

Pushed by gijskruitbosch@gmail.com: https://hg.mozilla.org/integration/autoland/rev/b5ed3294a9d7 don't use history for windowless browsers, r=farre https://hg.mozilla.org/integration/autoland/rev/a13bf582f195 release assert if something tries to start the history service before profile startup, r=mak
Pushed by gijskruitbosch@gmail.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/c2298e57e803 don't use history for windowless browsers, r=farre https://hg.mozilla.org/integration/mozilla-inbound/rev/c36ad62407f3 release assert if something tries to start the history service before profile startup, r=mak
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
Depends on: 1542397
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: