Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

node.js - Firebase Cloud Function Error: Process exited with code 16

I am getting this two errors in my Firebase console.

It seems it does not execute the Restart() function of my cloud function anymore.

I will post my cloud function below.

Until now I did not find a solution for this error.

Does someone know what could be the issue?

Error: Process exited with code 16
    at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:275:22)
    at process.emit (events.js:315:20)
    at process.EventEmitter.emit (domain.js:483:12)
    at process.exit (internal/process/per_thread.js:167:15)
    at Object.sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:37:9)
    at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:271:22)
    at process.emit (events.js:315:20)
    at process.EventEmitter.emit (domain.js:483:12)
    at processPromiseRejections (internal/process/promises.js:209:33)
    at processTicksAndRejections (internal/process/task_queues.js:98:32)

Error: set
    at Repo.abortTransactionsOnNode_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:14740:67)
    at Repo.abortTransactions_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:14701:10)
    at Repo.setWithPriority (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:12685:33)
    at Reference.set (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:13775:19)
    at /workspace/bot2.js:39:27
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

And this is my function:

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
//admin.initializeApp();

exports.bot2 = functions.database.ref('/users/-BOT2QMlrb5yV1D5R-rP/health')
    .onUpdate(async (change, context) => {
        const before = change.before.val();  // DataSnapshot before the change
        const after = change.after.val();  // DataSnapshot after the change
        console.log('health = ', after);

        if (before === after) {
            console.log("Health didn't change");
            return null;
        }

        var clicker = (await admin.database().ref('/users/-BOT2QMlrb5yV1D5R-rP/clickedby/').once('value')).val();

        admin.database()
            .ref('/users/-BOT2QMlrb5yV1D5R-rP/clickedby/')
            .on('value', function (snapshot) {
                clicker = snapshot.val();
            });

        console.log('clicker = ', clicker);

        var clickerclickedby = admin.database().ref('/users/' + clicker + '/clickedby');
        var clickerhealth = admin.database().ref('/users/' + clicker + '/health');
        var clickerscore = admin.database().ref('/users/' + clicker + '/score');

        if (after > 0 && after < 10) {
            clickerhealth.transaction(count => count - 1);
            clickerclickedby.set('-BOT2QMlrb5yV1D5R-rP');
        }

        if (after <= 0) {
            clickerscore.transaction(count => count + 1);
            clickerhealth.set(10);
            change.after.ref.parent.child('score').set(0);
            //setTimeout(() => change.after.ref.parent.child('health').set(10),3000);
            setTimeout(Restart, 3000, change.after.ref.parent);
        }
        return null;
    })

function Restart(ref) {
    ref.child('score').set(0);
    ref.child('health').set(10);
}

Here are the logs I have downloaded from Logs Explorer:

[
  {
    "textPayload": "Error: set
    at Repo.rerunTransactionQueue_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:14589:67)
    at Repo.rerunTransactions_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:14494:10)
    at /workspace/node_modules/@firebase/database/dist/index.node.cjs.js:14473:19
    at /workspace/node_modules/@firebase/database/dist/index.node.cjs.js:11900:17
    at PersistentConnection.onDataMessage_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:11930:17)
    at Connection.onDataMessage_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:11247:14)
    at Connection.onPrimaryMessageReceived_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:11241:18)
    at WebSocketConnection.onMessage (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:11142:27)
    at WebSocketConnection.appendFrame_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:10728:18)
    at WebSocketConnection.handleIncomingFrame (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:10779:22)",
    "insertId": "000000-2ce372c8-9948-4e76-98a1-ceb56f596e86",
    "resource": {
      "type": "cloud_function",
      "labels": {
        "function_name": "bot2",
        "region": "us-central1",
        "project_id": "battle-click"
      }
    },
    "timestamp": "2021-01-17T13:01:22.948Z",
    "severity": "ERROR",
    "labels": {
      "execution_id": "ekcpygd17zks"
    },
    "logName": "projects/battle-click/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
    "trace": "projects/battle-click/traces/044ed44b50a138d4de4a95383a11c935",
    "receiveTimestamp": "2021-01-17T13:01:27.347188676Z"
  },
  {
    "textPayload": "Error: Process exited with code 16
    at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:275:22)
    at process.emit (events.js:315:20)
    at process.EventEmitter.emit (domain.js:483:12)
    at process.exit (internal/process/per_thread.js:167:15)
    at Object.sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:37:9)
    at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:271:22)
    at process.emit (events.js:315:20)
    at process.EventEmitter.emit (domain.js:483:12)
    at processPromiseRejections (internal/process/promises.js:209:33)
    at processTicksAndRejections (internal/process/task_queues.js:98:32)",
    "insertId": "000000-7c13e8b3-0595-41e4-901c-4a6e2643994d",
    "resource": {
      "type": "cloud_function",
      "labels": {
        "function_name": "bot2",
        "project_id": "battle-click",
        "region": "us-central1"
      }
    },
    "timestamp": "2021-01-17T13:01:24.044Z",
    "severity": "ERROR",
    "labels": {
      "execution_id": "ekcpygd17zks"
    },
    "logName": "projects/battle-click/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
    "trace": "projects/battle-click/traces/044ed44b50a138d4de4a95383a11c935",
    "receiveTimestamp": "2021-01-17T13:01:27.347188676Z"
  },
  {
    "textPayload": "Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging Request rejected.
",
    "insertId": "000000-162167fa-fc24-4f1e-96a1-1595b973136b",
    "resource": {
      "type": "cloud_function",
      "labels": {
        "project_id": "battle-click",
        "function_name": "bot2",
        "region": "us-central1"
      }
    },
    "timestamp": "2021-01-18T11:00:21.419911849Z",
    "severity": "ERROR",
    "labels": {
      "execution_id": ""
    },
    "logName": "projects/battle-click/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
    "receiveTimestamp": "2021-01-18T11:00:21.760209675Z"
  },
  {
    "textPayload": "Error: set
    at Repo.abortTransactionsOnNode_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:14740:67)
    at Repo.abortTransactions_ (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:14701:10)
    at Repo.setWithPriority (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:12685:33)
    at Reference.set (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:13775:19)
    at /workspace/bot2.js:39:27
    at processTicksAndRejections (internal/process/task_queues.js:97:5)",
    "insertId": "000000-0efc4e49-5776-4aea-938f-385f2340f032",
    "resource": {
      "type": "cloud_function",
      "labels": {
        "project_id": "battle-click",
        "function_name": "bot2",
        "region": "us-central1"
      }
    },
    "timestamp": "2021-01-23T21:57:15.830Z",
    "severity": "ERROR",
    "labels": {
      "execution_id": "4cifdb3v583i"
    },
    "logName": "projects/battle-click/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
    "trace": "projects/battle-click/traces/50790baa80493a267baf9024017d515a",
    "receiveTimestamp": "2021-01-23T21:57:18.243185578Z"
  },
  {
    "textPayload": "Error: Process exited with code 16
    at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:275:22)
    at process.emit (events.js:315:20)
    at process.EventEmitter.emit (domain.js:483:12)
    at process.exit (internal/process/per_thread.js:167:15)
    at Object.sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:37:9)
    at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:271:22)
    at process.emit (events.js:315:20)
    at process.EventEmitter.emit (domain.js:483:12)
    at processPromiseRejections (internal/process/promises.js:209:33)
    at processTicksAndRejections (internal/process/task_queues.js:98:32)",
    "insertId": "000000-c3fd188b-c84f-4782-904f-e4ba42cc8c09",
    "resource": {
      "type": "cloud_function",
      "labels": {
        "region": "us-central1",
        "project_id": "battle-click",
        "function_name": "bot2"
      }
    },
    "timestamp": "2021-01-23T21:57:16.866Z",
    "severity": "ERROR",
    "labels": {
      "execution_id": "4cifdb3v583i"
    },
    "logName": "projects/battle-click/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
    "trace": "projects/battle-click/trac

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...