From 2e57f90bd1b5f06e948b84a61b8c2a32d31b706b Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Thu, 31 Jan 2019 08:38:25 +0000 Subject: [FIX] web: fixed leak on image fields During the unit tests, I have noticed that the test window was doing a lot of work after the test were completed, it was using CPU and using RAM in jigsaw pattern. Eventually after being left alone for a few hours, the window would just crash. This was due to an unlimitted chain of deferred running when an image field had a load error. The situation is as such: 1. The image is put in the DOM with an onError handler 2. There is an error, as the image is a dummy text for the tests 3. The onError is called, it clears the image field, then calls _render 4. _render re-adds an image with the same onError handler <---------- 5. The onError is called - again - it clears the image field - again | (wich does nothing this time because the value is the same) - | then calls _render - again | 6. The second time _render is called, go to step 4 -------------------- ... In the meantime, the widget has been destroyed by the test, so it should not do anything anymore. This fix breaks the loop, as well as bind the onError handled with 'one' instead of 'on'. closes odoo/odoo#30716 --- addons/web/static/src/js/fields/basic_fields.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 4d266db409d..b3cd17a38ee 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1501,9 +1501,13 @@ var AbstractFieldBinary = AbstractField.extend({ * @private */ _clearFile: function (){ + var self = this; this.set_filename(''); - this._setValue(false); - this._render(); + if (!this.isDestroyed()) { + this._setValue(false).then(function() { + self._render(); + }); + } }, //-------------------------------------------------------------------------- @@ -1573,7 +1577,7 @@ var FieldBinaryImage = AbstractFieldBinary.extend({ } this.$('> img').remove(); this.$el.prepend($img); - $img.on('error', function () { + $img.one('error', function () { self._clearFile(); $img.attr('src', self.placeholder); self.do_warn(_t("Image"), _t("Could not display the selected image.")); -- cgit v1.2.3