【发布时间】:2017-12-26 14:39:54
【问题描述】:
我在使用 Google Cloud PubSub API 时遇到了一些问题。最近,我开始使用 Cloud PubSub 为我正在开发的聊天服务器排队消息。来自 PubSub 订阅的消息使用 socket.io 节点库转发给用户。设置这个我没有问题 - 我运行我的 node.js 服务器,打开几个浏览器窗口,我可以毫无问题地聊天。
但是,我注意到,通常在服务器运行几个小时后,它开始吐出以下错误:
(node:2525) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
(node:2525) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
...
(node:2525) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1253): Error: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential...
此错误不断重复(您可以在错误消息中看到递增的rejection id),直到几分钟后停止并且事情恢复正常。当我收到错误消息时,我无法通过 Cloud PubSub 发送任何消息。
这是设置监听器的代码:
function listenForMessages(handler)
{
var pubsub = require('@google-cloud/pubsub')({
projectId: config.pubsub_project_id,
keyFilename: config.pubsub_keyfile
});
pubsub.subscribe(config.pubsub_topic, 'test-subscription', {autoAck: true}, function(err, subscription){
subscription.on('message', function(message) {
handler(message.data);
});
});
}
凭据来自外部配置文件 - 我很确定它们没问题,特别是考虑到在我最初运行服务器时设置侦听器没有问题。
TL;DR:在我开始运行使用 Google Cloud PubSub 对消息进行排队的节点服务器几个小时后,我开始反复收到“无效凭据”错误。
【问题讨论】:
-
我最近也有这个问题。奇怪的是,我从 10 个不同的队列中提取了大约 10 个不同的微服务,但这只会发生在一个特定的队列上。是的,它通常需要几天到一周的时间才能出现,但似乎经常发生。
-
另外,如果可以更准确地总结问题,我会更改标题。承诺拒绝只是偶然的。主要问题是它在一段时间后随机失去授权。编辑:我试图自己编辑标题。
-
好的,接受新标题。谢谢。
标签: node.js oauth google-cloud-platform google-cloud-pubsub