Google Cloud PubSub:以前有效的订阅突然未经授权

我在使用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); }); }); } 

凭据来自外部configuration文件 – 我敢肯定,他们没事,特别是当我最初运行服务器时没有设置监听器的麻烦。

TL; DR:在开始运行使用Google Cloud PubSub排列邮件的节点服务器后的几个小时内,我开始重复出现“无效凭据”错误。