Work around a race condition(?) causing issues on startup

See lengthy comment inside main.js added in this commit.
This commit is contained in:
Gina Häußge 2016-08-31 15:50:33 +02:00
parent 9e1f82d977
commit 20607dfab0
2 changed files with 17 additions and 4 deletions

View file

@ -558,7 +558,20 @@ $(function() {
callViewModels(allViewModels, "onStartup");
viewModelMap["settingsViewModel"].requestData()
.done(bindViewModels);
.done(function() {
// There appears to be an odd race condition either in JQuery's AJAX implementation or
// the browser's implementation of XHR, causing a second GET request from inside the
// completion handler of the very same request to never get its completion handler called
// if ETag headers are present on the response (the status code of the request does NOT
// seem to matter here, only that the ETag header is present).
//
// Minimal example with which I was able to reproduce this behaviour can be found
// at https://gist.github.com/foosel/b2ddb9ebd71b0b63a749444651bfce3f
//
// Decoupling all consecutive calls from this done event handler hence is an easy way
// to avoid this problem. A zero timeout should do the trick nicely.
window.setTimeout(bindViewModels, 0);
});
});
}
);

View file

@ -460,6 +460,9 @@ $(function() {
// perform the request
self.receiving(true);
return OctoPrint.settings.get()
.always(function() {
self.receiving(false);
})
.done(function(response) {
self.fromResponse(response, local);
@ -483,9 +486,6 @@ $(function() {
deferred.reject(args);
});
self.outstanding = [];
})
.always(function() {
self.receiving(false);
});
};