1

My firebase functions opens up a sql transactions and does a series of inserts. While that functions works in my local and CI system, it does not work while connected to Google SQL Postgres

I get timeout error. Following is the log. Any thoughts ?

5:02:29.925 pm myApp Function execution took 20280 ms, finished with status code: 500
5:02:29.915 pm myApp TimeoutError: ResourceRequest timed out
    at ResourceRequest._fireTimeout (/user_code/node_modules/sequelize/node_modules/generic-pool/lib/ResourceRequest.js:62:17)
    at Timeout.bound (/user_code/node_modules/sequelize/node_modules/generic-pool/lib/ResourceRequest.js:8:15)
    at ontimeout (timers.js:386:11)
    at tryOnTimeout (timers.js:250:5)
    at Timer.listOnTimeout (timers.js:214:5)
5:02:29.914 pm myApp Error Express : ResourceRequest timed out
5:02:29.911 pm myApp Executing (1963639b-91e6-42c9-acdf-8cb6463d5150): ROLLBACK;
5:02:09.904 pm myApp Executing (1963639b-91e6-42c9-acdf-8cb6463d5150): INSERT INTO ...... RETURNING *;
5:02:09.893 pm myApp Executing (1963639b-91e6-42c9-acdf-8cb6463d5150): START TRANSACTION;
Muthukumar
  • 8,679
  • 17
  • 61
  • 86

1 Answers1

0

After some search found it. In production I was using a pool size of "1" (as recommend for firebase functions). In the sequelize transaction, I had few select queries without transaction enforced. Due to which the non-transaction query was in need of separate connection. The Tran query waits for non-tran to complete. But non-tran cannot proceed since it need a connection which is held up by the tran query. Hence it timedout.

Best explained here. https://github.com/sequelize/sequelize/issues/7884#issuecomment-338778283

After correcting the select queries to be part of the same transaction, the problem solved.

Muthukumar
  • 8,679
  • 17
  • 61
  • 86
  • Can you share the code you used to connect from firebase to google? I am having a terrible time, finding something that works. – 1252748 Dec 31 '19 at 04:36
  • 1
    @1252748 left a comment in https://stackoverflow.com/questions/59537323/using-cloud-sql-proxy-from-firebase-function/59540029#59540029 – Muthukumar Dec 31 '19 at 05:40