Retry limit exceeded when uploading file
Environment details
- OS: Ubuntu Server 16.04
- Node.js version: v10.15.3
- npm version: 6.4.1
@google-cloud/storageversion: 2.5.0
Steps to reproduce
- 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!'));
}
});
});
}
- 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!
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()
@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.
I recall that we used the solution presented by dhauptman on this SO post.
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.
I am closing this issue, please reopen if you still experience the same issue.