Repository navigation
Closed
Labels
api: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
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.
/*Google Cloud Functions used in this project*/
/**
* Triggered from a message on a Cloud Pub/Sub topic.
*
* @param {!Object} event The Cloud Functions event.
* @param {!Function} The callback function.
*/
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();
};Metadata
Metadata
Assignees
Labels
api: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Activity
lukesneeringer commentedon Mar 29, 2017
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).
lukesneeringer commentedon Mar 29, 2017
Possibly related to #2139.
stephenplusplus commentedon Mar 30, 2017
@leonardoam is there a way to find out which version of
@google-cloud/commonis being loaded? We sent through a fix recently that was released with @google-cloud/common@0.12.2, which would hopefully resolve this.stephenplusplus commentedon Mar 30, 2017
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.
lukesneeringer commentedon Mar 31, 2017
@leonardoam Release party is happening now, so this should be good to go in a couple hours.
leonardoam commentedon Mar 31, 2017
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.
lukesneeringer commentedon Mar 31, 2017
@leonardoam Should be fixed in the newest version, which for storage is 1.0.0.
Chandler commentedon Apr 28, 2017
What is the newest version? I'm seeing this error on "@google-cloud/storage@1.1.0" inside of a Google Cloud Functions routine.
it's not happening for every queue item, it's sporadic.
FreakTheMighty commentedon Jan 8, 2018
I too am confused. What modules need to be updated to what version to resolve this issue?
adirzoari commentedon Apr 15, 2018
@Chandler same issue, it's happen sometimes. did you find solution??
feat: (observability): trace Database.runTransactionAsync (#2167)
feat(observability): fix bugs found from product review + negative ca…
chore(main): release 7.15.0 (#2118)