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 #2438Labels 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. DescriptionWe 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);
}Activitystephenplusplus commented on Jul 8, 2017 @ofrobots ever run into anything like this before? deremer commented on Jul 10, 2017 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 lukesneeringer commented on Jul 10, 2017 I too am hoping @ofrobots will have an idea. :-)
@deremer Can you provide the actual stack trace? deremer commented on Jul 10, 2017 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"
}
deremer commented on Jul 10, 2017 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"
}
ofrobots commented on Jul 10, 2017 ofrobots commented on Jul 10, 2017 The error indicates a TCP read error – which suggests that sporadically there are some network issues in the environment? ofrobots commented on Jul 10, 2017 deremer commented on Jul 10, 2017 @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. murgatroid99 commented on Jul 10, 2017 Note: the part with the metadata is probably irrelevant. That is trailing response metadata, which is often empty. murgatroid99 commented on Jul 10, 2017 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). deremer commented on Jul 10, 2017 @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? murgatroid99 commented on Jul 10, 2017 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. deremer commented on Jul 11, 2017 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 juanparadox commented on Sep 11, 2019 Any work arounds for this issue? JustinBeckwith commented on Sep 11, 2019 Not currently, but we're making progress on a fix alexander-fenster commented on Sep 11, 2019 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! bcoe commented on Sep 17, 2019 deremer commented on Sep 18, 2019
@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. bcoe commented on Oct 8, 2019 bcoe commented on Oct 9, 2019 @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. felixmpaulus commented on Dec 16, 2019 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' }
JustinBeckwith commented on Dec 16, 2019 Greetings! Could you open a new issue with details? locked as resolved and limited conversation to collaborators on Dec 16, 2019
MetadataMetadatapriority: 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. DevelopmentNo branches or pull requestsIssue actions
|