nodejs-storage icon indicating copy to clipboard operation
nodejs-storage copied to clipboard

Retry limit exceeded when uploading file

Open amber-cd opened this issue 7 years ago • 5 comments

Environment details

  • OS: Ubuntu Server 16.04
  • Node.js version: v10.15.3
  • npm version: 6.4.1
  • @google-cloud/storage version: 2.5.0

Steps to reproduce

  1. We run the following code from our environment (revised slightly to remove our personal data and extraneous variables):
function minimum_replication(installationId, contentType) {
	return new Promise((resolve, reject) => {
		bucket = gcs.bucket(installationId);
		bucket.exists((error, exists) => {
			// once we know if it exists
			if (exists) {
				var options = {
					predefinedAcl: 'private',
					destination: 'private/folder/subfolder/Report - sample_report.csv',
					metadata: {
						contentType: contentType,
						cacheControl: 'no-cache'
					}
				};
				// Add in a check here for if the bucket exists
				let file = new File(bucket, destPath);

				fs.createReadStream('sample_file.csv')
					.pipe(file.createWriteStream(options))
					.on('error', function (err) {
						console.error('err', err);
						return reject(err);
					})
					.on('finish', function () {
						console.log('resolving');
						return resolve();
					});
			} else {
				return reject(new Error('uploadToGCS Error: Bucket does not exist!'));
			}
		});
	});
}
  1. We receive the following errors in our console:
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit
err Error: Retry limit exceeded
    at Upload.onResponse (/home/amber_cd/projects/action-processor-v2/node_modules/gcs-resumable-upload/build/src/index.js:360:30)
    at Upload.<anonymous> (/home/amber_cd/projects/action-processor-v2/node_modules/gcs-resumable-upload/build/src/index.js:324:18)
    at Generator.next (<anonymous>)
    at fulfilled (/home/amber_cd/projects/action-processor-v2/node_modules/gcs-resumable-upload/build/src/index.js:10:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)

We've been in contact with Google support, and they recommended we file a new ticket on this project.

Thanks!

amber-cd avatar Apr 24 '19 17:04 amber-cd

Hi @amber-cd, are you still bumping in the issue? I tried with the following way and it worked for me. Also, you can try it and let me know if it works for you.

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const fs = require('fs');

function test(){
    return new Promise((resolve, reject) => {
        storage.bucket('[BUCKET_NAME]').exists((err, exists) => {
            if (exists){
                var options = {
                            predefinedAcl: 'private',
                            destination: '[DESTINATION_PATH]',
                            metadata: {
                                contentType: [CONTENT_TYPE],
                                cacheControl: 'no-cache'
                            }   
                }
                const File = storage.bucket('[BUCKET_NAME]').file('[FILE_NAME]');
                fs.createReadStream('[LOCAL_FILE]')
                .on('error', function (err) {
                    console.log(err)
                })
                .pipe(File.createWriteStream(options))
                .on('error', function (err) {   
                    console.error(err);
                    return reject(err);
                })
                .on('finish', () => {
                    console.log('resolved',null,File,File.metadata);
                    return resolve();
                })
            }else{
                console.log('Error :- ',err);
            }
        });
    })
}
test()

vishald123 avatar Jun 06 '19 11:06 vishald123

@amber-cd Retry limit exceeded message is not the original error message, hence making it hard to pinpoint the actual cause of the problem. With googleapis/gcs-resumable-upload/pull/240 now you should be able to see the original error message.

If you are still experiencing the issue, could you please post the log of the actual error message here.

AVaksman avatar Aug 14 '19 17:08 AVaksman

I recall that we used the solution presented by dhauptman on this SO post.

amber-cd avatar Aug 14 '19 17:08 amber-cd

MaxListenersExceededWarning warning is a separate issue. It occurs only in case of multiple retries, however in order to retry, it has to fail first. When an original failure occurs the library will retry up to (currently) 5 times before returning an error. Somewhere on the forth retry a MaxListenersExceededWarning is emitted, however it is not the cause of the problem and this warning will not cause an error to be returned. As I mentioned earlier Retry limit exceeded is not the original error that caused the failure. As of right now if a failure occurs the library will populate the original culprit error message.

As far as setting options.resumable to false, it is recommended on files smaller than 10MB, but only due to possible performance degradation due to an occurring overhead.

If you sill come across of the same issue with options.resumable: true (the default behavior) please post the log here.

AVaksman avatar Aug 15 '19 04:08 AVaksman

I am closing this issue, please reopen if you still experience the same issue.

AVaksman avatar Aug 22 '19 03:08 AVaksman