GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Error: Endpoint read failed at /user_code/node_modules/@google-cloud/logging/node_modules/grpc/src/node/src/client.js:569:15 · Issue #2438 · googleapis/google-cloud-node

Error: Endpoint read failed at /user_code/node_modules/@google-cloud/logging/node_modules/grpc/src/node/src/client.js:569:15 #2438

New issue
Copy link
New issue
Copy link
Closed
googleapis/nodejs-spanner
#145
googleapis/nodejs-spanner#145
Closed
Error: Endpoint read failed at /user_code/node_modules/@google-cloud/logging/node_modules/grpc/src/node/src/client.js:569:15#2438
googleapis/nodejs-spanner
#145
Copy link
Assignees
murgatroid99alexander-fenster
Labels
priority: p2Moderately-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.

Description

@deremer
deremer
opened on Jul 6, 2017
Issue body actions

We are using Stack Driver to log errors for Firebase functions. We unpredictably get the error in the title. Typically it happens the first to we try to log an error after a function re-deploys. Subsequent error log writes will go through to StackDriver without issue, but occasionally we'll get the error again.

We're using "@google-cloud/logging": "^1.0.2", and deployed via Firebase Functions.

Below is our module that implements the logging...

Anybody have any idea what is causing this?

const Logging = require('@google-cloud/logging');

// To keep on top of errors, we should raise a verbose error report with Stackdriver rather
// than simply relying on console.error. This will calculate users affected + send you email
// alerts, if you've opted into receiving them.
const logging = Logging();

// This is the name of the StackDriver log stream that will receive the log
// entry. This name can be any valid log stream name, but must contain "err"
// in order for the error to be picked up by StackDriver Error Reporting.
const logName:string = 'errors-fb-func';

// Enum of StackDriver severities
enum Severities {
  ERROR = 500, // ERROR	(500) Error events are likely to cause problems.
  CRITICAL = 600, // CRITICAL	(600) Critical events cause more severe problems or outages.
  ALERT = 700, // ALERT	(700) A person must take an action immediately.
  EMERGENCY = 800 // EMERGENCY	(800) One or more systems are unusable.
}

// Provide an error object and and optional context object
export function log(err:Error, logLevel:number=Severities.ERROR, user?:string): Promise<any> {
  // https://cloud.google.com/functions/docs/monitoring/error-reporting#advanced_error_reporting

  const FUNCTION_NAME = process.env.FUNCTION_NAME;
  const log = logging.log(logName);

  const metadata = {
    // MonitoredResource
    // See https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/MonitoredResource
    resource: {
      // MonitoredResource.type
      type: 'cloud_function',
      // MonitoredResource.labels
      labels: {
       function_name: FUNCTION_NAME
      }
    },
    severity: logLevel
  };

  const context:any = {};
  if (user && typeof user === 'string') {
    // ErrorEvent.context.user
    context.user = user;
  }

  // ErrorEvent
  // See https://cloud.google.com/error-reporting/reference/rest/v1beta1/ErrorEvent
  let structPayload:any = {
    // ErrorEvent.serviceContext
    serviceContext: {
      // ErrorEvent.serviceContext.service
      service: `cloud_function:${FUNCTION_NAME}`,
      // ErrorEvent.serviceContext.version
      resourceType: 'cloud_function'
    },

  };

  if (context) {
    // ErrorEvent.context
    structPayload.context = context;
  }

  structPayload.message = getMsgForError(err);

  return writeLog(log, metadata, structPayload);
}

function getMsgForError(error:Error): string {
  // https://cloud.google.com/functions/docs/monitoring/error-reporting#advanced_error_reporting
  // ErrorEvent.message
  if (error instanceof Error && typeof error.stack === 'string') {
    return error.stack;
  } else if (typeof error === 'string') {
    return error;
  } else if (typeof error.message === 'string') {
    return error.message;
  } else {
    logFatalError(error, "Error message type not supported");
    return "";
  }
}

function writeLog(log:any, metadata:any, structPayload:any): Promise<any> {
  console.log(metadata);
  console.log(structPayload);
  // Write the error log entry
  return new Promise((resolve, reject) => {
    try {
      log.write(log.entry(metadata, structPayload), (error:any) => {
        if (error) {
          logFatalError(error);
          reject(error);
        }
        resolve();
      });
    } catch(error) {
      reject(error);
    }
  });
}

// Utility function to log error if Logger fails
function logFatalError(error:Error, msg?:string): void {
  console.error(error, msg);
  throw error;
}

// error, crtical, alert, emergency, accept an Error object
// And then set error.stack as the message
export function error(error:Error, user?:string): Promise<any> {
  return log(error, Severities.ERROR, user);
}

export function critical(error:Error, user?:string): Promise<any> {
  return log(error, Severities.CRITICAL, user);
}

export function alert(error:Error, user?:string): Promise<any> {
  return log(error, Severities.ALERT, user);
}

export function emergency(error:Error, user?:string): Promise<any> {
  return log(error, Severities.EMERGENCY, user);
}

Activity

Next
  1. stephenplusplus commented on Jul 8, 2017

    @stephenplusplus
    stephenplusplus
    on Jul 8, 2017
    Contributor
    More actions

    @ofrobots ever run into anything like this before?

  2. stephenplusplus
    added
    api: loggingIssues related to the Cloud Logging API.
    on Jul 8, 2017
  3. deremer commented on Jul 10, 2017

    @deremer
    deremer
    on Jul 10, 2017
    Author
    More actions

    As an update, it seems to be more of an issue the first time a call is made to Stackdriver after a Firebase function is updated and restarted. Subsequent requests seem to go through ok. Although it does re-emerge sporadically. We really haven't been able to get to the bottom of it.

    Unfortunately, this causes the functions to timeout and throw an "Unhandled Exception", which is not going to work for us in production. So unless we can resolve this issue, we will have to replace Stackdriver with another logger.

    Reacted by Anonymous and Farmaan Elahi
  4. lukesneeringer commented on Jul 10, 2017

    @lukesneeringer
    lukesneeringer
    on Jul 10, 2017
    Contributor
    More actions

    I too am hoping @ofrobots will have an idea. :-)

    @deremer Can you provide the actual stack trace?

  5. deremer commented on Jul 10, 2017

    @deremer
    deremer
    on Jul 10, 2017
    Author
    More actions

    Here is one log entry where we see this...

    {
     insertId:  "000000-6ca1de21-3818-4c66-a620-a8a02227e1a7"   
     labels: {
      execution_id:  "134720017564250"    
     }
     logName:  "projects/REDACTED/logs/cloudfunctions.googleapis.com%2Fcloud-functions"   
     receiveTimestamp:  "2017-07-10T00:12:20.477133425Z"   
     resource: {
      labels: {
       function_name:  "LotteryActions"     
       project_id:  "REDACTED"     
       region:  "us-central1"     
      }
      type:  "cloud_function"    
     }
     severity:  "ERROR"   
     textPayload:  "{ Error: Endpoint read failed
        at /user_code/node_modules/@google-cloud/logging/node_modules/grpc/src/node/src/client.js:569:15 code: 14, metadata: Metadata { _internal_repr: {} } } undefined"   
     timestamp:  "2017-07-10T00:12:14.178Z"   
    }
    
  6. deremer commented on Jul 10, 2017

    @deremer
    deremer
    on Jul 10, 2017
    Author
    More actions

    I've been wondering if we're setting metadata incorrectly or something because of the metadata: Metadata { _internal_repr: {} } } undefined

    But here's another one where it doesn't have that...

    {
     insertId:  "000001-901cb19e-a4cb-4c78-a339-360408edb7d8"   
     labels: {
      execution_id:  "134720017564250"    
     }
     logName:  "projects/REDACTED/logs/cloudfunctions.googleapis.com%2Fcloud-functions"   
     receiveTimestamp:  "2017-07-10T00:12:20.477133425Z"   
     resource: {
      labels: {
       function_name:  "LotteryActions"     
       project_id:  "REDACTED"     
       region:  "us-central1"     
      }
      type:  "cloud_function"    
     }
     severity:  "ERROR"   
     textPayload:  "Error: Endpoint read failed
        at /user_code/node_modules/@google-cloud/logging/node_modules/grpc/src/node/src/client.js:569:15"   
     timestamp:  "2017-07-10T00:12:14.179Z"   
    }
    
  7. ofrobots commented on Jul 10, 2017

    @ofrobots
    ofrobots
    on Jul 10, 2017
    Contributor
    More actions

    /cc @GoogleCloudPlatform/node-team @murgatroid99

  8. ofrobots commented on Jul 10, 2017

    @ofrobots
    ofrobots
    on Jul 10, 2017
    Contributor
    More actions

    The error indicates a TCP read error – which suggests that sporadically there are some network issues in the environment?

  9. ofrobots commented on Jul 10, 2017

    @ofrobots
    ofrobots
    on Jul 10, 2017
    Contributor
    More actions

    @swalkowski @jasonpolites: any ideas if this could be an issue on Functions?

  10. deremer commented on Jul 10, 2017

    @deremer
    deremer
    on Jul 10, 2017
    Author
    More actions

    @ofrobots Just so future readers are 100% clear on this... This code is being run as Firebase Functions, so it's 100% within the Google Cloud environment.

  11. murgatroid99 commented on Jul 10, 2017

    @murgatroid99
    murgatroid99
    on Jul 10, 2017
    More actions

    Note: the part with the metadata is probably irrelevant. That is trailing response metadata, which is often empty.

  12. murgatroid99 commented on Jul 10, 2017

    @murgatroid99
    murgatroid99
    on Jul 10, 2017
    More actions

    It seems like the gRPC client successfully establishes a TCP connection (if it didn't, the error would say "Connect failed"), then the first attempt to read from that TCP connection fails for some reason, and the request it was a part of failed.

    It might help to see more details of the TCP error, but that doesn't propagate far enough up the stack. It is possible to see it (along with a torrent of other information) by setting the environment variables GRPC_TRACE=tcp GRPC_VERBOSITY=DEBUG. The trace information from that gets dumped to stderr, so if you have access to that, that could help (though it could also expose too much information).

  13. deremer commented on Jul 10, 2017

    @deremer
    deremer
    on Jul 10, 2017
    Author
    More actions

    @murgatroid99 any idea how to set an env var like that with Firebase Functions...or through the Cloud Function console?

    Put it in runtime.config.json?

  14. murgatroid99 commented on Jul 10, 2017

    @murgatroid99
    murgatroid99
    on Jul 10, 2017
    More actions

    I am not familiar with Cloud Functions, but you should just be able to do process.env.GRPC_TRACE='tcp'; and process.env.GRPC_VERBOSITY=DEBUG'; in the JS file before loading the logging module.

  15. deremer commented on Jul 11, 2017

    @deremer
    deremer
    on Jul 11, 2017
    Author
    More actions

    We were experimenting with a few things and one thing we try is moving const logging = Logging(); inside the log() function. Since we've done that we haven't seen the error.

    If ok, can we leave this open for a couple of days so that I can report back on if that fixed it or not?

    If that is in fact the issue, then Firebase may want to update their docs: https://firebase.google.com/docs/functions/reporting-errors#importing_dependencies

    Reacted by Asa Downs
  16. 85 remaining items

  17. JustinBeckwith
    assigned
    murgatroid99
    and
    alexander-fenster
    and unassigned
    JustinBeckwith
    on Aug 24, 2019
  18. juanparadox commented on Sep 11, 2019

    @juanparadox
    juanparadox
    on Sep 11, 2019
    More actions

    Any work arounds for this issue?

  19. JustinBeckwith commented on Sep 11, 2019

    @JustinBeckwith
    JustinBeckwith
    on Sep 11, 2019
    Contributor
    More actions

    Not currently, but we're making progress on a fix

    Reacted by Juan Bernal
  20. alexander-fenster commented on Sep 11, 2019

    @alexander-fenster
    alexander-fenster
    on Sep 11, 2019
    Contributor
    More actions

    Hi folks,

    We made some changes in @grpc/grpc-js grpc/grpc-node#1021 that might fix the problem described here. They are releases as v0.5.3. Can I bother you updating, checking if the issue is still here with v0.5.3, and sending the stack trace back if something still does not work?

    Thanks!

  21. bcoe commented on Sep 17, 2019

    @bcoe
    bcoe
    on Sep 17, 2019
    More actions

    @deremer 👋 hey, I just wanted to check in and see if @alexander-fenster's changes in @grpc/grpc-js helped?

  22. deremer commented on Sep 18, 2019

    @deremer
    deremer
    on Sep 18, 2019
    Author
    More actions

    @deremer 👋 hey, I just wanted to check in and see if @alexander-fenster's changes in @grpc/grpc-js helped?

    We haven’t had a release to deploy with updated dependencies yet. I will report back once we do so and get some data. Lots of other folks on here too so they might see results sooner.

  23. bcoe commented on Oct 8, 2019

    @bcoe
    bcoe
    on Oct 8, 2019
    More actions

    @deremer @juanparadox @kyle-mccarthy, can you folks confirm that the latest release of @google-cloud/logging has addressed this issue for you?

  24. bcoe commented on Oct 9, 2019

    @bcoe
    bcoe
    on Oct 9, 2019
    More actions

    @deremer I'm going to go ahead and close this issue, because it's been almost a month, and seems like things have been working okay for folks.

    Please feel free to re-open if you are continuing to bump into these issues.

  25. bcoe
    closed this as completedon Oct 9, 2019
  26. bcoe
    removed
    🚨This issue needs some love.
    on Oct 9, 2019
  27. felixmpaulus commented on Dec 16, 2019

    @felixmpaulus
    felixmpaulus
    on Dec 16, 2019
    More actions

    This error popped up this morning for the first time.

    { Error: 14 UNAVAILABLE: TCP Read failed
        at Object.exports.createStatusError (/srv/node_modules/grpc/src/common.js:91:15)
        at Object.onReceiveStatus (/srv/node_modules/grpc/src/client_interceptors.js:1204:28)
        at InterceptingListener._callNext (/srv/node_modules/grpc/src/client_interceptors.js:568:42)
        at InterceptingListener.onReceiveStatus (/srv/node_modules/grpc/src/client_interceptors.js:618:8)
        at callback (/srv/node_modules/grpc/src/client_interceptors.js:845:24)
      code: 14,
      metadata: Metadata { _internal_repr: {} },
      details: 'TCP Read failed' }
    
  28. JustinBeckwith commented on Dec 16, 2019

    @JustinBeckwith
    JustinBeckwith
    on Dec 16, 2019
    Contributor
    More actions

    Greetings! Could you open a new issue with details?

  29. googleapis
    locked as resolved and limited conversation to collaborators on Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @alexander-fenster
    alexander-fenster
  • @murgatroid99
    murgatroid99

Labels

priority: p2Moderately-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.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.