Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(uploader): only monitor the queue being idle when we kow we are finishing the upload #1521

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ export class Uploader {
}
this.destination = destinationFolder

// Reset when upload queue is done
this._jobQueue.addListener('idle', () => this.reset())

logger.debug('Upload workspace initialized', {
destination: this.destination,
root: this.root,
Expand Down Expand Up @@ -157,12 +154,18 @@ export class Uploader {
}

private reset() {
// If there is no upload in the queue and no job in the queue
if (this._uploadQueue.length === 0 && this._jobQueue.size === 0) {
return
}

// Reset upload queue but keep the reference
this._uploadQueue.splice(0, this._uploadQueue.length)
this._jobQueue.clear()
this._queueSize = 0
this._queueProgress = 0
this._queueStatus = Status.IDLE
logger.debug('Uploader state reset')
}

/**
Expand Down Expand Up @@ -595,6 +598,16 @@ export class Uploader {
this._jobQueue.add(request)
this.updateStats()
}

// Reset when upload queue is done
// Only when we know we're closing on the last chunks
// and/or assembling we can reset the uploader.
// Otherwise he queue might be idle for a short time
// and clear the Upload queue before we're done.
this._jobQueue.onIdle()
.then(() => this.reset())

// Finally return the Upload
return upload
}) as PCancelable<Upload>

Expand Down
4 changes: 4 additions & 0 deletions lib/utils/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { getCurrentUser } from '@nextcloud/auth'
import axios from '@nextcloud/axios'
import axiosRetry, { exponentialDelay } from 'axios-retry'

import logger from './logger'

axiosRetry(axios, { retries: 0 })

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

logger.debug('Created temporary upload workspace', { url })

return url
}
Loading