I am using a node.js function on Google Cloud Functions to save Pub/Sub messages to GCS (Storage), but it randomly gives me the following error for some messages (most of the messages are succesfully written):
"Error: Could not authenticate request. Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information."
It doesn't make sense, once running on GCE would use same service-account for all messages, which has the proper permissions, and all messages comes from the same source and goes to the same destination. Can someone enlighten me on what could I do?
I'm using google-cloud/storage version 0.8.0.
```js
/Google Cloud Functions used in this project/
/**
const bucketName = 'backup-queue-bucket';
const util = require('util')
const gcs = require('@google-cloud/storage')();
const crypto = require('crypto');
exports.backupQueue = function backupQueue(event, callback) {
// The Cloud Pub/Sub Message object.
const timestamp = event.timestamp;
const resources = event.resource.split('/');
const pubsubMessage = event.data;
const messageContent = Buffer.from(pubsubMessage.data, 'base64').toString();
// We're just going to log the message to prove that
// it worked.
var queueName = resources[resources.length-1];
console.log(`Message received: ${messageContent} in queue ${queueName}`);
const filename = timestamp+'_'+crypto.createHash('md5').update(messageContent).digest('hex');
const bucket = gcs.bucket(bucketName);
const file = bucket.file(queueName+'/'+filename);
const fs = file.createWriteStream({});
fs.on('finish', function () {
console.log(`Message ${filename} successfully written to file.`);
});
fs.on('error', function (error) {
console.warn(`Message ${filename} could not be written to file. Retry will be called. Error: ${error.message}`);
setTimeout(backupQueue(event, callback), 1000);
});
fs.write(Buffer.from(pubsubMessage.data, 'base64').toString());
fs.end();
callback();
};
Hi @leonardoam. Thanks for reporting.
At the moment, I am just acking your issue. I am not sure what to do (but giving it some background thought while I hope someone else speaks up).
Possibly related to #2139.
@leonardoam is there a way to find out which version of @google-cloud/common is being loaded? We sent through a fix recently that was released with @google-cloud/[email protected], which would hopefully resolve this.
Sorry @leonardoam, that was bad information. We didn't actually release the fix yet, but I am even more certain now that it will resolve this issue. This issue is another flavor of #1908, which reported this same error in Compute Engine environments.
I'm going to close and try to remember to ping you when we release an update (hopefully the coming days), and we'll re-investigate if it turns out not to be the fix. Sorry for the trouble.
@leonardoam Release party is happening now, so this should be good to go in a couple hours.
Thanks guys. What version will this fix affect?
Last ocurrence happened at 14:49 BRT, I will keep monitoring and let you know if this fixed the issue.
@leonardoam Should be fixed in the newest version, which for storage is 1.0.0.
What is the newest version? I'm seeing this error on "@google-cloud/[email protected]" inside of a Google Cloud Functions routine.
Error: Could not authenticate request Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.
at wrapError (/user_code/node_modules/@google-cloud/storage/node_modules/gcs-resumable-upload/index.js:24)
at (/user_code/node_modules/@google-cloud/storage/node_modules/gcs-resumable-upload/index.js:268)
at (/user_code/node_modules/@google-cloud/storage/node_modules/google-auto-auth/index.js:25)
at (/user_code/node_modules/@google-cloud/storage/node_modules/google-auto-auth/index.js:173)
at process._tickDomainCallback (next_tick.js:129)
it's not happening for every queue item, it's sporadic.
I too am confused. What modules need to be updated to what version to resolve this issue?
@Chandler same issue, it's happen sometimes. did you find solution??
Most helpful comment
What is the newest version? I'm seeing this error on "@google-cloud/[email protected]" inside of a Google Cloud Functions routine.
it's not happening for every queue item, it's sporadic.