0

I'm facing a weird behaviour, and I don't know where to look anymore.

Here is the bug : When I upload a file, it starts then stops after 2 or 3 "progress" events. Then nothings happened, it just hang there forever. The file is written on the disk, and the beginning of the picture is there (like 20%) and that's it.

When does the bug happened :

  • if I use PM2 to launch my app, with node vers 14 or 16 or 18 or 20

When does it work normally :

  • if i run the app without PM2
  • if i run the app with PM2 and node v12
  • I I send really small files, like 3KB

What I tried already :

  • originally I was using skipper-s3, but realize I have the same behaviour with skipper (save on disk) so the problem is not from there
  • I tried to upload the file in amazon without skipper, same behaviour (works without PM2, doesn't work with PM2)
  • I'm currently trying to change the body parser, or the body parser options, as it seems it could be related but I'm not sure what to do there.
  • I tried to add a "await sleep(3000)" function just after the file upload to let him the time to finish uploading, but it still get stuck
  • I had the problem with PM2 4.5, I've updated it to 5.3.0 but I still have the issue

Here is my code where it get stucks (only with PM2)

console.log("There is at least one file to upload, start upload");
req.file('attachment').upload({
    // don't allow the total upload size to exceed ~10MB
    maxBytes: 10000000,
    onProgress: function (o) {
        console.log("progess ", o.written);
    }
}, function whenDone(err, uploadedFiles) {

    console.log("upload completed"); //WE NEVER GETS HERE
    console.log(err);
    if (err) {
        return res.serverError(err);
    }
});

// const sleep = ms => new Promise(r => setTimeout(r, ms));
// await sleep(3000);//Wait 3 sec to leave a bit of delay before the retry 

console.log("AFTER FILE upload");

And this is an output

There is at least one file to upload, start upload
AFTER FILE upload
progess  22770
progess  22771
progess  48962
progess  65372

Then it stops here. The example file is 124KB on my disk, and only 64KB has been uploaded.

The uploaded file looks like this : buggy uploaded file

Any help, even just an idea in which direction to look would be appreciated

Francois
  • 93
  • 1
  • 15

1 Answers1

0

I Finally understood the problem if this helps anyone :

PM2 was configured to also used AWS X-RAY monitonring. And this was making the request to abort before file was completely uploaded.

Francois
  • 93
  • 1
  • 15