-
Notifications
You must be signed in to change notification settings - Fork 9
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
有时无法访问到 this.app.mysql #6
Comments
此外,有时是 this.ctx.service 中的对象无法访问到,我不得不用 |
今天继续调试,现在是在 listener 的 run 里
打印 ctx 发现,无法访问时是
可以访问时是
区别是前者没有 ctx.app.serviceClasses,后者有。不清楚为什么 ctx.app.serviceClasses 会消失? |
初步判断可能是和 worker 有关,稍后确认一下,感谢反馈。 |
app.mysql 无法访问 在 config.mysql = {
client: {
host: 'localhost',
port: '3306',
user: 'root',
password: 'secret',
database: 'test',
},
app: true,
agent: true, // <-- 置为 true
}; service 无法访问 这是由 'use strict';
module.exports = app => {
const ctx = app.createAnonymousContext();
console.log(ctx.service); // undefined
}; 目前无法确定是写法不对还是 egg 的 bug,已经提交相关 issue 至 egg(eggjs/egg#3946),等待反馈结果。 可以先自己手动使用 |
有时无法访问到ctx.service。。。 |
在 Listener 中添加方法访问 this.app.mysql,观察到诡异的情况:有几次能正常访问,有时则提示
TypeError: Cannot read property 'queryOne' of undefined
类似下图,前两次正常执行,最后一次突然出现错误提示。
The text was updated successfully, but these errors were encountered: