Google Cloud PubSub: Previously Valid Subscription Unexpectedly Unauthorized

I'm having problems with the Google Cloud PubSub API. I recently started using Cloud PubSub to queue messages on the chat server I'm working on. Messages from a PubSub subscription are sent to users using the socket.io node library. I have no problems with the setup - I launch my node.js server, open a couple of browser windows, and I can communicate without problems.

However, I noticed that often after the server has been running for several hours, it starts to spit out the following error:

(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: " " node, Google Cloud PubSub .

+4

Source: https://habr.com/ru/post/1681905/


All Articles