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

【eggjs】npm start 后,中间件中的代码一直被执行。 #3678

Closed
luckymore opened this issue May 5, 2019 · 5 comments
Closed

Comments

@luckymore
Copy link

问题复现

1、中间件代码
sharp_rotate.js

'use strict'
module.exports = () => {
  return async function sharpRotate(ctx, next) {
    const start = Date.now()
    await next()
    console.log('rotate 时间消耗: ', Date.now() - start, 'ms')
  }
}

2、中间件配置
config.default.js

middleware: ['sharpRotate', 'errorHandler'],

3、执行 npm start
本地mac OS环境正常
linux-64环境中间件代码一直被执行

image.png

最小可复现仓库

https://github.com/luckymore/middleware-test.git

相关环境信息

  • 操作系统:CentOS Linux release 7.0.1406 (Core)
  • Node 版本:v8.9.2
  • Egg 版本:2.22.2
@atian25
Copy link
Member

atian25 commented May 5, 2019

从代码上看不出问题,如果只是你在 linux 上有这个问题的话,建议打印下 ctx.url 以及抓包看看,是不是 linux 上有什么定时任务啥的。

@luckymore
Copy link
Author

@atian25 是新的空白的容器,只有一个supervisor守护进程的东东,定时任务怎么会执行到中间件里去了呢?不是只有请求进来的时候代码才会执行嘛?

@atian25
Copy link
Member

atian25 commented May 5, 2019

我指的是 linux 自身的 cron 啥的。

或者是 supervisor 之类会不会有监控检查之类的请求。你在你的中间件里面打印下 ctx 的 url, headers 等信息查下呗。

@popomore
Copy link
Member

popomore commented May 5, 2019

一直被执行是啥意思

@luckymore
Copy link
Author

@atian25 感谢猪哥, 找到问题啦,确实有个监控请求一直在访问我的服务,,,问下运维同学

@atian25 atian25 closed this as completed May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants