Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add lock init for egg app #622

Merged
merged 3 commits into from
Aug 30, 2020
Merged

fix: add lock init for egg app #622

merged 3 commits into from
Aug 30, 2020

Conversation

czy88840616
Copy link
Member

@czy88840616 czy88840616 commented Aug 30, 2020

app(egg) 迁移方案会不知道为何在冷启动时初始化多次。报错如下:

{
    "errorMessage": "EMFILE: too many open files, open '/code/package.json'",
    "errorType": "Error",
    "stackTrace": [
        "at openSync (fs.js:457:3)",
        "at readFileSync (fs.js:359:35)",
        "at exports.readJSONSync (/code/node_modules/utility/lib/json.js:19:24)",
        "at EggLoader (/code/node_modules/egg-core/lib/loader/egg_loader.js:45:24)",
        "at AgentWorkerLoader (/code/node_modules/@midwayjs/egg-layer/node_modules/egg/lib/loader/agent_worker_loader.js:9:1)",
        "at EggCore (/code/node_modules/egg-core/lib/egg.js:118:19)",
        "at EggApplication (/code/node_modules/@midwayjs/egg-layer/node_modules/egg/lib/egg.js:46:5)",
        "at Agent (/code/node_modules/@midwayjs/egg-layer/node_modules/egg/lib/agent.js:22:5)",
        "at LayerWrapper (/code/node_modules/@midwayjs/egg-layer/framework/index.js:8:12)",
        "at module.exports (/code/node_modules/@midwayjs/egg-layer/node_modules/egg/lib/start.js:31:17)"
    ]
}

猜测原因:

  • 1、初始化超时(报错),导致在 invoke 时并发又进行初始化
  • 2、fc 并发调用 initializer,比如配置了单实例多并发(概率小,因为默认是单实例,每次也只会有一个流量进来)
  • 3、框架运行时未调用 initializer 方法初始化,而是从 invoke 初始化(测试了下排除)

Action:

  • 1、发现 egg 启动,如果默认开了 static 插件,导致会往目录结构里写文件(app/public),导致报错,默认禁用 static
  • 2、加入初始化方法锁
  • 3、延长初始化时间(3s -> 10s),只对支持 initTimeout 的有效

@gitpod-io
Copy link

gitpod-io bot commented Aug 30, 2020

@czy88840616 czy88840616 merged commit ccb5fe5 into serverless Aug 30, 2020
@czy88840616 czy88840616 deleted the add_lock_init branch August 30, 2020 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants