googleapis / nodejs-storage

Node.js client for Google Cloud Storage: unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
https://cloud.google.com/storage/
Apache License 2.0
903 stars 370 forks source link

Cannot call write after a stream was destroyed #2546

Closed raviradadiya0142 closed 3 weeks ago

raviradadiya0142 commented 1 month ago

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Node.js version : 16 "@google-cloud/storage": 7.11.3

Error during file upload NodeError: Cannot call write after a stream was destroyed 8|unipin-node-live | at doWrite (/home/unipin/unipin_nodejslive/node_modules/readable-stream/lib/_stream_writable.js:390:38) 8|unipin-node-live | at writeOrBuffer (/home/unipin/unipin_nodejslive/node_modules/readable-stream/lib/_stream_writable.js:381:5) 8|unipin-node-live | at Writable.write (/home/unipin/unipin_nodejslive/node_modules/readable-stream/lib/_stream_writable.js:302:11) 8|unipin-node-live | at HashStreamValidator.ondata (node:internal/streams/readable:809:22) 8|unipin-node-live | at HashStreamValidator.emit (node:events:517:28) 8|unipin-node-live | at addChunk (node:internal/streams/readable:368:12) 8|unipin-node-live | at readableAddChunk (node:internal/streams/readable:341:9) 8|unipin-node-live | at Readable.push (node:internal/streams/readable:278:10) 8|unipin-node-live | at HashStreamValidator._transform (/home/unipin/unipin_nodejslive/node_modules/@google-cloud/storage/build/cjs/src/hash-stream-validator.js:95:14) 8|unipin-node-live | at Transform._write (node:internal/streams/transform:175:8)

const file = cloudStorage.bucket(bucketName).file(fileName); return new Promise(async (resolve, reject) => { try { // Directly save the file content await file.save(fileData.buffer, { metadata: { contentType: fileData.mimetype, }, resumable: false, // Set to false as we're not using streams, validation:false });

    // Get the signed URL
    const [url] = await file.getSignedUrl({
      action: 'read',
      expires: '03-01-2500', // Set the appropriate expiration date
    });
    console.log(url,"url");

    resolve(url);
  } catch (err) {
    console.error('Error during file upload', err);
    reject(err);
  }
});
raviradadiya0142 commented 1 month ago

error Error: Failed to upload file: Cannot call write after a stream was destroyed at Writable. (/home/unipin/unipin_nodejslive/src/utils/fileUpload.js:199:20) at Writable.emit (node:events:529:35) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

ddelgrosso1 commented 1 month ago

@raviradadiya0142 how frequently are you running into this problem? I'm assuming the exception gets thrown during the save call but just want to make sure this code never actually reaches the getSignedUrl portion, is that accurate? Any different behavior if you use resumable: true or validation not set to false?

ddelgrosso1 commented 3 weeks ago

Ran some tests this morning and have been unable to recreate this. If you can supply more information, please feel free to reopen.