Firebase函数在连接到Google Cloud Sql时引发TimeoutError

时间:2018-12-22 11:40:05

标签: postgresql google-cloud-functions google-cloud-sql

我的firebase函数打开一个sql事务并执行一系列插入操作。虽然该功能在我的本地和CI系统中有效,但在连接到Google SQL Postgres时不起作用

我收到超时错误。以下是日志。有什么想法吗?

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;

1 个答案:

答案 0 :(得分:0)

经过一些搜索后发现它。在生产中,我使用的池大小为“ 1”(如针对Firebase函数的建议)。在顺序事务中,没有执行事务的情况下,我只有很少的选择查询。因此,非事务查询需要单独的连接。 Tran查询等待非tran完成。但是非tran无法继续,因为它需要由tran查询保留的连接。因此它超时了。

最佳解释在这里。 https://github.com/sequelize/sequelize/issues/7884#issuecomment-338778283

将选择查询更正为同一事务的一部分后,问题得以解决。