question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File upload randomly crashes

See original GitHub issue

The bug report won’t be as thorough as I hoped and since this happens so rarely and without any notice we haven’t been able to reproduce this locally - sorry about that.

We have a service that runs a job every hour. It reads a DB and creates CSV files, and uploads them to Google Cloud Storage. Each job saves a few thousand files at about 150 KB each. A few times a month or so it randomly crashes and in our logs we find two different errors. These does not occur at the same time so might not be related, but both of them happens “randomly” and both errors include an unhandled error event in Duplexify.

Missing a file and retrying is fine, but the crash takes down our pod and makes us loose a lot of files.

The unhandled error starts in file.js in createWriteStream() when calling fileWriteStream.destroy(error).

I might be wrong there, but both of these would normally fail gracefully, but the unhandled error in Duplexify makes them crash? Would fixing this be a solution, or should one look further into the reason for destroying at the first place? Has anyone experienced similar behaviour?

Errors

events.js:292
 throw er; // Unhandled 'error' event
 ^

RequestError: The uploaded data did not match the data from the server. As a precaution, the file has been deleted. To be sure the content is the same, you should try uploading the file again. at ... /node_modules/@google-cloud/storage/build/src/file.js:1336:35 at ... /node_modules/@google-cloud/common/build/src/util.js:367:25 at Util.handleResp (... /node_modules/@google-cloud/common/build/src/util.js:144:9) at ... /node_modules/@google-cloud/common/build/src/util.js:432:22 at onResponse (... /node_modules/retry-request/index.js:214:7) at ... /node_modules/teeny-request/build/src/index.js:219:17 at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:97:5)
Emitted 'error' event on Pumpify instance at:
 at errorOrDestroy (internal/streams/destroy.js:108:12)
 at Pumpify.onerror (_stream_readable.js:753:7)
 at Pumpify.emit (events.js:315:20)
 at Pumpify.Duplexify._destroy (... /node_modules/pumpify/node_modules/duplexify/index.js:195:15)
 at ... /node_modules/pumpify/node_modules/duplexify/index.js:185:10
 at processTicksAndRejections (internal/process/task_queues.js:79:11) {
 code: 'FILE_NO_UPLOAD',
 errors: [ null ]
}
events.js:292
 throw er; // Unhandled 'error' event
 ^

Error: Upload failed at Upload.<anonymous> (... /node_modules/gcs-resumable-upload/build/src/index.js:188:30) at Upload.emit (events.js:327:22) at Upload.onResponse (... /node_modules/gcs-resumable-upload/build/src/index.js:383:14) at Upload.makeRequestStream (... /node_modules/gcs-resumable-upload/build/src/index.js:332:14) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Upload.startUploading (... /node_modules/gcs-resumable-upload/build/src/index.js:216:13)
Emitted 'error' event on Pumpify instance at:
 at errorOrDestroy (internal/streams/destroy.js:108:12)
 at Pumpify.onerror (_stream_readable.js:753:7)
 at Pumpify.emit (events.js:315:20)
 at Pumpify.Duplexify._destroy (... /node_modules/pumpify/node_modules/duplexify/index.js:195:15)
 at ... /node_modules/pumpify/node_modules/duplexify/index.js:185:10
 at processTicksAndRejections (internal/process/task_queues.js:79:11)

Code:

  const filePath = "TEST/device/system/2021/01/01/09.csv"

  storeNewFile = async (
    file: File,
    data: Data[]
  ): Promise<void> => {
    const storage = new Storage( xxx );
    const bucket = storage.bucket("myBucket");
    const file = bucket.file(filePath);
    
    const csv : string = await convertJsonToCsv(JSON.stringify(data), true);

    return new Promise<void>((resolve, reject) => {
      const input = new Readable();
      input.pipe(file.createWriteStream());

      input.on("end", resolve);
      input.on("error", reject);

      input.push(csv);
      input.push(null);
    });
  };

Environment details

  • OS: node:12-alpine docker image (our prod environment)
  • Node.js version: 12.22.6
  • npm version: 6.14.15
  • @google-cloud/storage version: 4.7.0
  • Typescript: 3.7.3

EDIT: I posted wrong code snippet. We do not append to any existing files, but create a new ones.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:36 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
ddelgrosso1commented, Oct 6, 2021

@ErlendFax using save should retry in v5 of the library. I am taking a closer look at createWriteStream as well (which should also retry).

1reaction
ddelgrosso1commented, Nov 19, 2021

Thank you for the information @ErlendFax. I will run some experiments on our side and take a look at upload times pre/post changes. I may ultimately close out this issue and open another as it appears the original problem has been resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

System files crash on uploading files online and programs ...
So whenever I try to change directories in the File Explorer in any program, it will crash the program. Like 90% of the...
Read more >
The upload window keep crashing and closing by itself
Whenever I open the window to browse a file or a folder, the window shutdown or the whole software crashes. Please, help.
Read more >
VS randomly crashes when I tried to open a file or add a ...
You are able to get the files with the following steps: 1. Start Visual Studio. 2. Start another instance of VS. 3. Select...
Read more >
Freezing entire computer on file upload randomly.
Random freezes on file upload, possible large files like images but pretty much any file, once this happens i guess it gets in...
Read more >
7 Fixes If Windows Explorer Keeps Crashing - RevoUninstaller
Method 1: Clear Windows Explorer History; Method 2: Run System File Checker; Method 3: Update your Windows OS; Method 4: Disable 3rd-Party ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found