ngx-uploader icon indicating copy to clipboard operation
ngx-uploader copied to clipboard

Cancel and cancelAll upload

Open fatalcaron opened this issue 8 years ago • 6 comments

Current behavior: (type: cancel) = On a list of files, when I cancel the current uploading file, it cancel the uploading but don't pass to the next uploading.

(type: cancelAll): It cancel all the list but when I import new files it doesn't restart the uploading.

Expected behavior: When I cancel one or more downloads, it must cancel (it is already the case) but when we import other files, it must restart the download.

Version:

  • ngx-uploader: 4.2.2
  • Angular: 5.2.0

fatalcaron avatar Jan 20 '18 18:01 fatalcaron

Is it a issue or I miss something ?

fatalcaron avatar Jan 24 '18 13:01 fatalcaron

its a known issue but cannot be solved inside the module. please check https://github.com/bleenco/ngx-uploader/issues/9 for a working sample.

jkuri avatar Jan 24 '18 13:01 jkuri

I'm not sure number 9 answers mine.

I have no problem importing files into the module but it is with the cancel feature.

I do not have the knowledge level to help you with Observables but it seems to me that the flow does not go to the next. I do not know if there is a way to do that...

Maybe a solution for the cancelAll, we should reinitalize the uploaderScheduler at the end of the case 'cancelAll' with a function like:

initUploadScheduler(concurrency: number): void {
	this.uploadScheduler = new Subject();

	this.uploadScheduler
		.mergeMap(upload => this.startUpload(upload), concurrency)
		.subscribe(uploadOutput => this.serviceEvents.emit(uploadOutput));
}

fatalcaron avatar Jan 26 '18 23:01 fatalcaron

What is the status here? I ran into the issue by cancelAll, but can not find the solution anywhere. Is there a workaround?

rlovasz avatar Nov 30 '18 10:11 rlovasz

@jkuri this one is not the same as #9 because it happens when there are more cancelled (and/or running) uploads than the value of the concurrency option. Let me explain why this one happens:

  • uploadScheduler is a Subject and every started upload Observable is merged by mergeMap operator but limited by concurrency option
  • on completion of the Observable returned by startUpload method mergeMap cleans up normally so far so good
  • on cancel the actual Subscription is subs array is unsubscribed (as it should) so when xhr is aborted and change to XMLHttpRequest.DONE state then although observer.next() and observer.complete() calls run they will not call complete because observer is already stopped
  • because observer have not been completed nor errored out so the observer in startUpload have not been completed (because neither error nor complete functions have been called)
  • because the observer of startUpload is the mergeMap operator (it maintains inner subscriptions) then the mergeMap operator can not clean up this Observable causing a hang up (and probably a memory leak too) when there are cancelled uploads

Subscription provides a method to add a tear down logic which is called on unsubscribe. We can use that to complete observer when unsubscribe happens. It won't complete it twice because completing it sets it to stopped and when it is stopped it won't do anything again.

I will create a PR today and post it here too. (Where can I find the CLA which I should sign?)

pbabcsany avatar Feb 06 '19 08:02 pbabcsany

OK, I can not reproduce this kind of behavior with the demo app which uses Angular 7 and RxJS 6. I use Angular 5.2 too and when I upgrade ngx-uploader to 7.1.0 then if I would like to upload a new file after cancel then it won't start until the previous one completes. My fix would solve that but the upload still completes in the background then (devtools show pending request instead of cancelled). I am not aware the changes between the two versions (namely the 4.2 line and 7.1.0) but since this makes it possible to bypass concurrency limits (or maybe I am missing something) then probably upgrading to Angular 7, RxJS 6 and ngx-uploader 7.1.0 can solve this issue in my case.

pbabcsany avatar Feb 06 '19 11:02 pbabcsany