![](/img/trans.png)
[英]Nodejs azure function app Error: connect ETIMEDOUT ipaddress:443
[英]Azure Function connect Azure PostgreSQL ETIMEDOUT, errno: -4039
我有一個Azure ( AZ ) Function 做了兩件事:
使用 Postman 進行測試,此 AF 本地主機響應時間 < 40 毫秒。 部署到雲端,將 URL 更改為 AZ,同樣的數據集,花了30 秒得到Status: 500 Internal Server Error
。
進行了搜索,認為可能是這種情況,我需要將訂閱量提高到昂貴的訂閱以避免冷啟動。
但更多的調查分別運行第 1 部分和第 2 部分並結合起來,發現:
status: 500
無論它單獨運行還是在第 1 部分之后運行,都沒有返回數據。 Application Insight
已啟用並添加了一個Diagnostic settings
:
以下查詢未發現錯誤/異常:
requests | order by timestamp desc |limit 100 // success is "true", time taken 30 seconds, status = 500
traces | order by timestamp desc | limit 30 // success is "true", time taken 30 seconds, status = 500
exceptions | limit 30 // no data returned
我的 pg 調用有多復雜? 標准連接,簡單短:
require('dotenv').config({ path: './environment/PostgreSql.env'});
const fs = require("fs");
const pgp = require('pg-promise')(); // () = taking default initOptions
require('dotenv').config({ path: './environment/PostgreSql.env'});
const fs = require("fs");
const pgp = require('pg-promise')(); // () = taking default initOptions
db = pgp(
{
user: process.env.PGuser,
host: process.env.PGhost,
database: process.env.PGdatabase,
password: process.env.PGpassword,
port: process.env.PGport,
ssl:
{
rejectUnauthorized: true,
ca: fs.readFileSync("./environment/DigiCertGlobalRootCA.crt.pem").toString(),
},
}
);
const pgTest = (nothing) =>
{
return new Promise((resolve, reject) =>
{
var sql = 'select * from schema.test()'; // test() does a select from a 2-row narrrow table.
db.any(sql)
.then
(
good => resolve(good),
bad => reject({status: 555, body: bad})
)
}
);
}
module.exports = { pgTest }
AF test1
是標准的httpTrigger
匿名訪問:
const x1 = require("package1");
...
const xx = require("packagex");
const pgdb = require("db");
module.exports = function(context)
{
try
{
pgdb.pgTest(1)
.then
(
good => {context.res={body: good}; context.done();},
bad => {context.res={body: bad}; context.done();}
)
.catch(err => {console.log(err)})
}
catch(e)
{ context.res={body: bad}; context.done(); }
}
筆記:
public access (allowed IP addresses)
pgAdmin
和psql
都運行得很快。 更新 1 , FunctionAppLogs | where TimeGenerated between ( datetime(2022-01-21 16:33:20).. datetime(2022-01-21 16:35:46) )
FunctionAppLogs | where TimeGenerated between ( datetime(2022-01-21 16:33:20).. datetime(2022-01-21 16:35:46) )
是因為我的 pg 網絡訪問設置為Public access
嗎?
我的 AZ pgDB 是一個靈活的服務器,當前Networking
是Public access (allowed IP address)
,並且我添加了一些帶有客戶端 IP 地址的防火牆規則。 我的假設是在 AZ 內允許訪問,但事實並非如此。
解決方案,只需選中此框:允許從 Azure 中的任何 Azure 服務公共訪問Settings -> Networking底部的此服務器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.