Determine when all prefs have been written to disk#7930
Conversation
|
@redmunds I tried it with your branch and I got crash on quit most of the time with only one exception. That exception is when I have some windows update running at the background. |
|
@RaymondLim I know that this is not the final fix. I created the pull request so you and @dangoor could look at the code and let me know if it's on the right track, cases that were missed, etc. |
|
@redmunds I put new discoveries in the issue. Thanks for fixing it. I think you're on the right track since it fixes the issue in the case of making some changes in the document. So I believe if you can resolve the dangling promises, then we find the right solution. |
|
@RaymondLim @dangoor With this branch, it now only seems to crash if you Quit immediately after opening. I'm wondering if preferences are still being initialized, but I was able to capture console once and I did not see that code tried to write a pref after being finalized (i.e. line 1563 ). Maybe need to add a Deferred object when loading prefs? |
|
@redmunds Yes, this does look like the right track to me. There would be a lot more potential places where it could crash immediately after opening if reads were a problem, too. There are promises for when preferences and viewstate are done loading, if that turned out to be the cause of the crash on quit. |
|
@dangoor @RaymondLim I added those promises, but I still crash sometimes when closing immediately after startup. I suppose there could be some non-Preferences startup code that's causing this. Anyway, try it out and let me know how it works. |
|
@redmunds Does it make sense to land this and then continue trying to track down other possible sources of the crash? |
|
@dangoor If you agree that there's nothing more that can be done as far as waiting on the prefs system (i.e. the problem is elsewhere), then, yes, I think this should merged into master. |
|
@redmunds I just took a look at GitHub doesn't want to show me the diff for this. // Return the promise for the `_nextSaveDeferred` if there is one.
// If there isn't, return the promise for the current save operation (if there is one).
// If there isn't one of those, return a resolved promise.
var deferred = this._nextSaveDeferred || this._saveInProgress || (new $.Deferred()).resolve();
deferred.done(function () {
this.finalized = true;
});
return deferred.promise();
It's better to assume that promises resolve asynchronously, even if that's not always the case with jQuery promises. If promises can resolve asynchronously, then it would be possible for a save to sneak in before // Return the promise for the `_nextSaveDeferred` if there is one.
// If there isn't, return the promise for the current save operation (if there is one).
// If there isn't one of those, return a resolved promise.
var deferred = this._nextSaveDeferred || this._saveInProgress;
if (!deferred) {
this.finalized = true;
return (new $.Deferred()).resolve().promise();
}
deferred.done(function () {
this.finalized = true;
}.bind(this));
return deferred.promise();may be safer. |
|
@dangoor Changes pushed.
Status: I did more testing with this fix and narrowed it down some more:
So, the remaining crash seems to point to JS Code Hints. |
|
The problem with the number 2 case in my comment above is that the deferred returned by |
|
@dangoor Immediately setting I checked in some JSDoc fixes and opened this JSDoc bug: jbalsas/apify#52 |
|
I'm still a little worried that if we leave a possibility open for this condition to be hit that we're going to see bugs on this filed down the line and have to go track it down afresh. If we do this in var deferred = this._nextSaveDeferred,
self = this;
if (!deferred) {
deferred = new $.Deferred();
function checkForSaveAndFinalize() {
if (self._saveInProgress) {
self._saveInProgress.done(checkForSaveAndFinalize);
} else {
self.finalized = true;
deferred.resolve();
}
}
checkForSaveAndFinalize();
} else {
deferred.done(function () {
self.finalized = true;
});
}
return deferred.promise();What do you think? Thanks for the doc fixes! |
|
@dangoor Ready for another review. I see -- we need to keep waiting until last last In your sample code, if there is a But, there will only ever be a It also simplifies the code a bit. |
|
Good call. That looks much nicer and seems reasonable. As long as this works as well as the last version for you, then this is ready to merge. |
|
@dangoor Yes, I am seeing same results, so go ahead and merge. Do you have any suggestions for a JS Code Hint promise that can be waited on to try to fix remaining issue described in this comment? Looks like |
Determine when all prefs have been written to disk
|
Branch merged (but not deleted... it probably makes more sense to start a new PR for the code hints stuff. Go ahead and delete the branch if you'll be making a new one.) Augmenting CodeHintManager for this specifically seems like we're spreading around knowledge of files that we're waiting on in a way that's hard to track. Perhaps we need the counterpart to AppInit (AppShutdown?) that calls callbacks which can return a promise for when it's safe to shutdown? |
This is for #7683.
This does not seem to always work. Posting for initial review.