alibaba / alibaba/funcraft

Node.js Initializer 函数无法在本地环境触发,发布到线上后可以触发

Open
#1,095 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
931
Forks
128
PR merge metrics
No merged PRs in 30d

Description

### 配置的Initializer函数在本地运行时无法触发,发布到线上后可以触发

配置和日志如下:

template.yml
```yml
ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
Puppeteer-service-screenshot:
Type: 'Aliyun::Serverless::Service'
Properties:
Description: Puppeteer screenshot service
Puppeteer-screenshot:
Type: 'Aliyun::Serverless::Function'
Properties:
Initializer: demo.initializer
InitializationTimeout: 180
Handler: demo.handler
Runtime: nodejs12
CodeUri: ./
MemorySize: 512
Timeout: 120
Events:
httpTrigger:
Type: HTTP
Properties:
AuthType: ANONYMOUS
Methods:
- GET
- POST
```

demo.js
```javascript
exports.initializer = function (context, callback) {
console.log('======> demo.js initializer() ');
callback(null, "");
}

exports.handler = function (request, response, context) {
console.log('======> demo.js handler() ');

response.setStatusCode(200);
response.setHeader('content-type', 'application/json');
response.send(JSON.stringify({}))
}
```

`fun local start`日志:
```text
using template: template.yml
HttpTrigger httpTrigger of Puppeteer-service-screenshot/Puppeteer-screenshot was registered
url: http://localhost:8000/2016-08-15/proxy/Puppeteer-service-screenshot/Puppeteer-screenshot/
methods: [ 'GET', 'POST', 'PUT' ]
authType: ANONYMOUS

function compute app listening on port 8000!

skip pulling image aliyunfc/runtime-nodejs12:1.9.13...
FC Initialize End RequestId: 6e845f13-b0b7-4872-9195-abdb4673c6e8, Error: Handled function error
FC Invoke Start RequestId: 6e845f13-b0b7-4872-9195-abdb4673c6e8
load code for handler:demo.handler
2021-03-15T05:37:48.650Z 6e845f13-b0b7-4872-9195-abdb4673c6e8 [verbose] ======> demo.js handler()
FC Invoke End RequestId: 6e845f13-b0b7-4872-9195-abdb4673c6e8
Error: Missing header x-fc-initialization-timeout

RequestId: 6e845f13-b0b7-4872-9195-abdb4673c6e8 Billed Duration: 279 ms Memory Size: 3938 MB Max Memory Used: 17 MB
```

`fun deploy`后`函数计算控制台`日志:
```text
FC Initialize Start RequestId: c02d7abe-a85c-47d0-9b3c-939d4747bf97
load code for handler:demo.initializer
2021-03-15T05:40:01.316Z c02d7abe-a85c-47d0-9b3c-939d4747bf97 [verbose] ======> demo.js initializer()
FC Initialize End RequestId: c02d7abe-a85c-47d0-9b3c-939d4747bf97
FC Invoke Start RequestId: c02d7abe-a85c-47d0-9b3c-939d4747bf97
load code for handler:demo.handler
2021-03-15T05:40:01.463Z c02d7abe-a85c-47d0-9b3c-939d4747bf97 [verbose] ======> demo.js handler()
FC Invoke End RequestId: c02d7abe-a85c-47d0-9b3c-939d4747bf97
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with template.yml and demo.js, then run the reported `fun local start` flow and compare its logs with the `fun deploy` logs. Trace the local initializer handling around `demo.initializer` and the missing `x-fc-initialization-timeout` header. Done means the local run invokes the initializer before `demo.handler` without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js
Domain
cli, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.