0

I have a node application which calls several google apis. It is deployed to cloud run, and I frequently see errors when it attempts to talk to googles APIs (I am using the google supplied node libraries). Errors take the form of:

{ "message": "request to https://oauth2.googleapis.com/token failed, reason: socket hang up", "type": "system", "errno": "ECONNRESET", "code": "ECONNRESET", "config": { "method": "POST", "url": "https://oauth2.googleapis.com/token", "data": "refresh_token=&client_id=&client_secret=&grant_type=refresh_token", "headers": { "Content-Type": "application/x-www-form-urlencoded", "User-Agent": "google-api-nodejs-client/8.1.0", "x-goog-api-client": "gl-node/16.16.0 auth/8.1.0", "Accept": "application/json" }, "body": "refresh_token=&client_id=&client_secret=&grant_type=refresh_token", "responseType": "json" } }

And

FetchError: request to https://gmail.googleapis.com/gmail/v1/users/me/messages/xxxxxformat=full failed, reason: Client network socket disconnected before secure TLS connection was established

They are not consistent, but happen pretty often, I've never seen this error when I run the apps locally, nor was it happening from app engine. Does anyone know any tricks to make outbound connections on cloud run less flakey?

Jake Hall
  • 1,963
  • 22
  • 24
  • Yes, there is a limit but that limit is not your problem. How fast/often are you connecting to gmail? Either you have a coding bug or your connection attempt is being dropped (rate limited, security, temporary network problem, etc.). – John Hanley Jul 12 '22 at 23:40
  • Initially i was making 100 connections at a time to retrieve messages, which works fine locally and in app engine. I've since reduced the simultaneous connections down to 10 then 1 from cloud run and still see a lot of issues, though once i added retry it seems to get past them most of the time. – Jake Hall Jul 13 '22 at 15:49
  • The error message indicates another issue with Google OAuth fetching/exchanging credentials. I think you are being rate limited. Without seeing your code design, I do not understand why you need so many connections or why you need to connect so often. OAuth tokens are valid for 3,600 seconds. That means cache them and only request new ones when required. – John Hanley Jul 13 '22 at 19:56
  • I found these [cases](https://stackoverflow.com/questions/65078917/nodejs-on-gce-error-client-network-socket-disconnected-before-secure-tls-connec), [2](https://stackoverflow.com/questions/53593182/client-network-socket-disconnected-before-secure-tls-connection-was-established) that can be useful with the error you are getting. – Andres Fiesco Casasola Jul 13 '22 at 21:15

0 Answers0