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

Infinite retries upon 500 response #297

Closed
kontrollanten opened this issue Apr 16, 2021 · 4 comments
Closed

Infinite retries upon 500 response #297

kontrollanten opened this issue Apr 16, 2021 · 4 comments

Comments

@kontrollanten
Copy link
Contributor

Describe the bug
When the server returns 500 upon file upload (PUT request) there's infinite retries.

To Reproduce

    this.uploadService.handleFiles(file, {
      endpoint: `${environment.apiUrl}/api/v1/videos/upload?uploadType=multipart`,
      multiple: false,
      token: this.authService.getAccessToken(),
    })

And then return 500 when the last part has been uploaded.

Expected behavior
A clear and concise description of what you expected to happen.
Setup details:

  • Used ngx-uploadx: 4.0.2
  • Used Angular version: 11.1.1
  • Used browser and OS: Linux, Brave
  • Used server software: Express 4.12.4

Additional context
When I'm debugging the code it looks like line 136 is reached before the server responded with 500.

while (this.status === 'uploading' || this.status === 'retry') {
this.status = 'uploading';
try {
this.url = this.url || (await this.getFileUrl());
this.offset = isNumber(this.offset) ? await this.sendFileContent() : await this.getOffset();
this.retry.reset();

@kukhariev
Copy link
Owner

kukhariev commented Apr 16, 2021

I tried this code:

  • express 4.17.1:
const options = new DiskStorage({
  directory: 'upload'
});
app.use('/upload/files', uploadx.upload(options), (req, res) => {
  res.sendStatus(500);
});
  • modified app/service-code-way/service-code-way.component.ts, angular 11.2.7 , build --prod:
@Component({
  selector: 'app-service-way',
  templateUrl: './service-code-way.component.html'
})
export class ServiceCodeWayComponent implements OnDestroy, OnInit {
  state$!: Observable<UploadState>;
  uploads: Ufile[] = [];
  numberOfCopies = 0;
  @ViewChild('file', { read: ElementRef })
  fileInput!: ElementRef;

  private unsubscribe$ = new Subject();

  constructor(private uploadService: UploadxService) {}
  onChange(): void {
    const files = this.fileInput.nativeElement.files;
    for (let i = 0; i < files.length; i++) {
      this.uploadService.handleFiles(files[i], {
        endpoint: `${environment.api}/upload/files`,
        multiple: false,
        token: 'token'
      });
    }
  }

  ngOnInit(): void {
    this.state$ = this.uploadService.init();
    this.state$.pipe(takeUntil(this.unsubscribe$)).subscribe(state => {
      const file = this.uploads.find(item => item.uploadId === state.uploadId);
      file ? file.update(state) : this.uploads.push(new Ufile(state));
    });
  }
...

Couldn't catch the error.
8 retry attempts or 5 retries if i set retryConfig: { maxAttempts: 5 }

sendFileContent() and getOffset() should always reject at code 500.

Only In uploader-examples\multipart-form-data.ts a similar error is possible.

@kontrollanten
Copy link
Contributor Author

Sorry, I wasn't clear enough. The issue appears when a 500 is returned when the file upload is completed.

@kukhariev
Copy link
Owner

kukhariev commented Apr 16, 2021

I don't get endless attempts.
2021-04-16_21-01-56

Is it possible to test with this server code (with correct PATH and PORT)?

const express = require('express');
const { uploadx } = require('node-uploadx');
//
const PATH = '/api/v1/videos/upload';
const PORT = 3003;
//
const app = express();
let retries = 0;
app.use(PATH, uploadx.upload({ directory: 'upload' }), (req, res) => {
  return res.status(500).json({ message: `is something wrong, ${retries++}` });
});

app.listen(PORT, () => console.log('listening on port:', PORT));

P.S.
endpoint: `${environment.apiUrl}/api/v1/videos/upload?uploadType=multipart`,
uploadType should not be used, it is only for the demo application.

@Chocobozzz
Copy link

I cannot reproduce either, but it would be convenient to have a shouldRetry function in https://github.com/kukhariev/ngx-uploadx/blob/master/src/uploadx/lib/retry-handler.ts#L53 because in our use case an error 500 is considered as fatal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants