Skip to content

Commit dc7cc82

Browse files
committed
Fix race condition when preparing upload folder
Before any upload is submitted the upload is registered in a list of known uploads; this is needed to retrieve the upload object at several points of the upload process. When a chunked upload is submitted first a directory to upload all the chunks is created and, once that is done, the chunks are sent; in order to send a chunk the upload object needs to be retrieved from the list of known uploads. When all the active uploads were finished the list of known uploads was cleared. However, an upload is not active until it actually starts sending the data, so while waiting for the upload directory to be created the upload is already in the list of known uploads yet not active. Due to all this, if the active uploads finished while another pending upload was waiting for the upload directory to be created that pending upload would be removed from the list of known uploads too, and once the directory was created and thus the chunks were sent a field of a null upload object would be accessed thus causing a failure. Instead of removing all the known uploads at once when the active uploads finish now each upload is explicitly removed when it finishes. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
1 parent b2a87f8 commit dc7cc82

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

apps/files/js/file-upload.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ OC.Uploader.prototype = _.extend({
576576
* Clear uploads
577577
*/
578578
clear: function() {
579-
this._uploads = {};
580579
this._knownDirs = {};
581580
},
582581
/**
@@ -595,6 +594,19 @@ OC.Uploader.prototype = _.extend({
595594
return null;
596595
},
597596

597+
/**
598+
* Removes an upload from the list of known uploads.
599+
*
600+
* @param {OC.FileUpload} upload the upload to remove.
601+
*/
602+
removeUpload: function(upload) {
603+
if (!upload || !upload.data || !upload.data.uploadId) {
604+
return;
605+
}
606+
607+
delete this._uploads[upload.data.uploadId];
608+
},
609+
598610
showUploadCancelMessage: _.debounce(function() {
599611
OC.Notification.show(t('files', 'Upload cancelled.'), {timeout : 7, type: 'error'});
600612
}, 500),
@@ -959,6 +971,8 @@ OC.Uploader.prototype = _.extend({
959971
}
960972
self.log('fail', e, upload);
961973

974+
self.removeUpload(upload);
975+
962976
if (data.textStatus === 'abort') {
963977
self.showUploadCancelMessage();
964978
} else if (status === 412) {
@@ -996,6 +1010,8 @@ OC.Uploader.prototype = _.extend({
9961010
var that = $(this);
9971011
self.log('done', e, upload);
9981012

1013+
self.removeUpload(upload);
1014+
9991015
var status = upload.getResponseStatus();
10001016
if (status < 200 || status >= 300) {
10011017
// trigger fail handler

0 commit comments

Comments
 (0)