```
The problem is that while `ProcessFoo()` is running in the background, the user might initiate browser shutdown. This results in the reply task `StoreProcessedFoo()` never being run (the BLOCK_SHUTDOWN trait only applies to the task posted to the ThreadPool, and IIUC, even if I somehow managed to post `StoreProcessedFoo()` back on the main thread with the BLOCK_SHUTDOWN trait, it would be ignored/"fizzled"). So the processed foo is lost.
Is there anything I can do to make sure `StoreProcessedFoo()` is run to prevent data loss?
---------
More context:
UMA histograms are backed by a file. In the `ProcessFoo()` above, what we actually do is remove these histograms from the file, and put them into a UMA proto. We then do some more processing like compressing.
Then, in `StoreProcessedFoo()`, we store this compressed UMA proto into Local State.
It's a problem if `StoreProcessedFoo()` is never run, because the histograms have already been removed from the file on disk, and the compressed UMA proto is not stored, resulting in data loss.
It's unfortunately not possible to only remove the histograms from disk after the compressed UMA proto is stored. I won't go into too much detail, but this could cause histograms being duplicated instead of lost.
My tentative solution to this (crrev.com/c/4780995) is to add some work in `PostDestroyThreads()` (IIUC, at this stage, all BLOCK_SHUTDOWN tasks have been finished, and all threads have been joined, so this is single-threaded). I check if there was some compressed UMA proto that was produced (but not yet stored), and if so, manually store it in Local State.
It seems to work fine, but there are some caveats. For example:
- 1) I need to ensure I do this work in all the various platform-specific PostDestroyThreads(),
- 2) On some platforms (Chromecast), it seems like Local State is already destroyed before PostDestroyThreads(). I suppose I could delay its destruction for my purposes but I don't know if that entails anything else.
Is there any better/canonical way to do this?
I think most of the experts are on a plane today, heading for a conference this week. You might want to ping the thread again next week if you don't get a response. (Sorry!)
--
You received this message because you are subscribed to the Google Groups "scheduler-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scheduler-de...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/scheduler-dev/CAORL5cPukHnX8NTpkPGjKf8LbCHnSN-PDdPYisNATto58U41vw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/scheduler-dev/CAORL5cO9rzJdYScq5Zjb0ZXQoVPgZ3zxZWHVD3%3DZYVuChaNqqg%40mail.gmail.com.
--
Is there some standard solution here?
For now, what I'm thinking is that in `CreateFooEvery30Minutes()`, if `is_shutting_down_` is true, then I call `ProcessFoo` and `StoreProcessedFoo` synchronously instead of thread hopping and doing the work on a background thread.
I think that would work, assuming that ScopedKeepAlive/KeepAliveRegistry are only interacted with on the main thread so that there's no race condition. (I don't see any DCHECKs/CHECKs or comments stating this though).
WDYT?
Thanks in advance!