pusongyang / todolist-backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lesson09 - rule-faas.js fc冷启动会超时

neyio opened this issue · comments

commented

打了很多断点不名所以,没尝试成功。

post|put|...请求(在带body参数)时 冷启动拉起超时。
比如

server.httpProxy(req, res, context);

对请求冷启动存在问题,如果已经启动了,那么任何请求都没有问题,该问题只在于冷启动。

做了以下尝试

// fc-express 中的HttpTriggerProxy 15行的代码 打断点body为Buffer[0],当然此处toString也是不成功的。

getRawBody(ctx.request, (err, body) => {
       req.write(body); 
       req.end();
});

不明白问题存在在哪,但是估计是bodyParser,或者是stream buffer的问题。

然后尝试修改入口为

module.exports.handler = function (req, res, context) {
  // return server.httpProxy(req, res, context);
  return getRawBody(req, function (_, body) {
    req.body = body.toString() || Buffer.from([]);
    server.httpProxy(req, res, context);
  });
};

好像没问题了

对node不怎么了解,希望能够指导下,谢谢🙏

你的FC函数初始化入口添加了这个没有?// 函数初始化入口:rule-faas.initializer

没有进一步回复,我先close了