Skip to content

Commit 36fafd8

Browse files
authored
Merge pull request #1521 from nextcloud-libraries/fix/queue-clear
2 parents e5cd087 + d51664e commit 36fafd8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/uploader.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ export class Uploader {
8888
}
8989
this.destination = destinationFolder
9090

91-
// Reset when upload queue is done
92-
this._jobQueue.addListener('idle', () => this.reset())
93-
9491
logger.debug('Upload workspace initialized', {
9592
destination: this.destination,
9693
root: this.root,
@@ -157,12 +154,18 @@ export class Uploader {
157154
}
158155

159156
private reset() {
157+
// If there is no upload in the queue and no job in the queue
158+
if (this._uploadQueue.length === 0 && this._jobQueue.size === 0) {
159+
return
160+
}
161+
160162
// Reset upload queue but keep the reference
161163
this._uploadQueue.splice(0, this._uploadQueue.length)
162164
this._jobQueue.clear()
163165
this._queueSize = 0
164166
this._queueProgress = 0
165167
this._queueStatus = Status.IDLE
168+
logger.debug('Uploader state reset')
166169
}
167170

168171
/**
@@ -595,6 +598,16 @@ export class Uploader {
595598
this._jobQueue.add(request)
596599
this.updateStats()
597600
}
601+
602+
// Reset when upload queue is done
603+
// Only when we know we're closing on the last chunks
604+
// and/or assembling we can reset the uploader.
605+
// Otherwise he queue might be idle for a short time
606+
// and clear the Upload queue before we're done.
607+
this._jobQueue.onIdle()
608+
.then(() => this.reset())
609+
610+
// Finally return the Upload
598611
return upload
599612
}) as PCancelable<Upload>
600613

lib/utils/upload.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { getCurrentUser } from '@nextcloud/auth'
88
import axios from '@nextcloud/axios'
99
import axiosRetry, { exponentialDelay } from 'axios-retry'
1010

11+
import logger from './logger'
12+
1113
axiosRetry(axios, { retries: 0 })
1214

1315
type UploadData = Blob | (() => Promise<Blob>)
@@ -102,5 +104,7 @@ export const initChunkWorkspace = async function(destinationFile: string | undef
102104
},
103105
})
104106

107+
logger.debug('Created temporary upload workspace', { url })
108+
105109
return url
106110
}

0 commit comments

Comments
 (0)