Google Cloud SQL No Answer

We are running the Sails.js API on the Google Container Engine with a cloud-based SQL database, and we recently discovered that some of our endpoints are at a dead end without ever sending a response.

I had a health check monitoring / v 1 / status, and it logged 100% uptime when I had the following simple answer:

status: function( req, res ){ res.ok('Welcome to the API'); } 

Once we have added the database query, the endpoint is the start of the timing. This does not always happen, but apparently by accident, sometimes for several hours in a row. This is what we changed the query to:

 status: function( req, res ){ Email.findOne({ value: " someone@example.com " }).then(function( email ){ res.ok('Welcome to the API'); }).fail(function(err){ res.serverError(err); }); } 

Rather, it is suspicious, all this works fine in our intermediate and development environments, it is only when deploying the code in production that there is a timeout and this only takes some time . The only thing that changes between the stage and the production is the database to which we are connecting and loading on the server.

As I mentioned earlier, we use Google Cloud SQL and Sails-MySQL . We have the following error stacks on a production server;

 AdapterError: Invalid connection name specified at getConnectionObject (/app/node_modules/sails-mysql/lib/adapter.js:1182:35) at spawnConnection (/app/node_modules/sails-mysql/lib/adapter.js:1097:7) at Object.module.exports.adapter.find (/app/node_modules/sails-mysql/lib/adapter.js:801:16) at module.exports.find (/app/node_modules/sails/node_modules/waterline/lib/waterline/adapter/dql.js:120:13) at module.exports.findOne (/app/node_modules/sails/node_modules/waterline/lib/waterline/adapter/dql.js:163:10) at _runOperation (/app/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:408:29) at run (/app/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:69:8) at bound.module.exports.findOne (/app/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:78:16) at bound [as findOne] (/app/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21) at Deferred.exec (/app/node_modules/sails/node_modules/waterline/lib/waterline/query/deferred.js:501:16) at tryCatcher (/app/node_modules/sails/node_modules/waterline/node_modules/bluebird/js/main/util.js:26:23) at ret (eval at <anonymous> (/app/node_modules/sails/node_modules/waterline/node_modules/bluebird/js/main/promisify.js:163:12), <anonymous>:13:39) at Deferred.toPromise (/app/node_modules/sails/node_modules/waterline/lib/waterline/query/deferred.js:510:61) at Deferred.then (/app/node_modules/sails/node_modules/waterline/lib/waterline/query/deferred.js:521:15) at Strategy._verify (/app/api/services/passport.js:31:7) at Strategy.authenticate (/app/node_modules/passport-local/lib/strategy.js:90:12) at attempt (/app/node_modules/passport/lib/middleware/authenticate.js:341:16) at authenticate (/app/node_modules/passport/lib/middleware/authenticate.js:342:7) at Object.AuthController.login (/app/api/controllers/AuthController.js:119:5) at bound (/app/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21) at routeTargetFnWrapper (/app/node_modules/sails/lib/router/bind.js:179:5) at callbacks (/app/node_modules/sails/node_modules/express/lib/router/index.js:164:37) 

 Error (E_UNKNOWN) :: Encountered an unexpected error : Could not connect to MySQL: Error: Pool is closed. at afterwards (/app/node_modules/sails-mysql/lib/connections/spawn.js:72:13) at /app/node_modules/sails-mysql/lib/connections/spawn.js:40:7 at process._tickDomainCallback (node.js:381:11) 

Looking only at errors, I will be tempted to say that we have something incorrectly configured. But the fact that it has been working for some time (and it worked fine earlier!) Makes me believe that there is some other black magic here. Our Cloud SQL instance is D0 (although we tried to increase the size to D4), and our activation policy is Always On.

EDIT: I saw others complaining about Google Cloud SQL, for example. this SO post , and I was suspicious, but since then we moved our database to Amazon RDS and we still see the same problems, so this should be a problem with sails and mysql.

This problem leads to hours of downtime per day, we need it, any help is greatly appreciated!

+5
source share
3 answers

This looks like a sail issue and is not necessarily related to cloud SQL.

+2
source

Is there any QPS limit for Google Cloud SQL? See here: https://cloud.google.com/sql/faq#sizeqps

+1
source

Why does my database instance sometimes respond slowly? To minimize the amount you pay for instances in billing plans, by default, your instance becomes passive if it is not available within 15 minutes. The next time it is available, there will be a slight delay when it is activated. You can change this behavior by setting up an instance activation policy. For example, see Editing an instance using the Cloud SDK.

This may be due to your policy settings. If you set it to ON_DEMAND, the instance will sleep to save your budget so that the first request to activate the instance is slow. This can lead to a timeout.

https://cloud.google.com/sql/faq?hl=en

+1
source

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


All Articles