0

I have a few google cloud functions which make use of the redis memory store and it gives me this Redis connection to :6379 failed - read ECONNRESET at TCP. onread error every time any of function deployed. Previously I shared the createClient() code with all of the functions by creating a separate util file and including them on the CFs, I thought that was the issue. But please note that this Redis cache is working as expected other than this error.

Then I tried putting util code inside each of the google cloud functions which use the redis client to create the client. But I'm still getting this error from every cloud functions when every I deploy any of a cloud function. Even when deploying the functions that do not use the redis.

Here's how I create a client :

const bluebird = require('bluebird');
const redis = bluebird.promisifyAll(require('redis'));

const cache = redis.createClient({ port: REDIS_PORT, host: REDIS_HOST });

cache.on("error",  (err) => {
  console.log("API One - Redis cache error : " + err);
});


const list = async(data) => {
 // Do something with data.
 let cachedData;
 if(cache.connected) { 
   await cache.hgetAsync(key); // Get cached Data.
 }

 // Do something with cached data if cachedData available.

 if(cache.connected) {
   await cache.hsetAsync(key, data); // Set Some Data.
 }

 return data;
}

module.exports = functions.https.onCall(list);

Why I'm seeing this error on every cloud function logs?

Sample error logs I get:

API One - Redis cache error : Error: Redis connection to <Ip Address>:6379 failed - read ECONNRESET
API Two - Redis cache error : Error: Redis connection to <Ip Address>:6379 failed - read ECONNRESET
Chamika Kasun
  • 96
  • 3
  • 16

1 Answers1

0

Have you tried closing the redis connection before the function finishes?

The redis module may have background callbacks active during the life of the client, not closing the connection prior to function termination may be causing the connection to timeout when the cloud function terminates. Make sure that all asynchronous operations finish before the function terminates.

For example: Example

Let me know if this works for you.

Stefan G.
  • 890
  • 5
  • 10
  • I did not try closing the connection, because I need to keep the connection alive to serve other requests from the API. There may be around 5 requests coming to this API per second. Not sure it is okay to close the connection every time with this request rate? [I updated the code further above and please have a look and advice me.] Thanks. – Chamika Kasun Sep 10 '19 at 03:33
  • Hello Chamika, I see that you've added the await but i think the error still resides in not actually closing the connection before terminating the function. Have a look at the following relevant information i found. Maybe it helps you. Attempt to close it at some point and see what happens, let me know and we can look further into it. [1](https://stackoverflow.com/a/57649161/11928097) – Stefan G. Sep 10 '19 at 07:48