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

1.r.57 IocBean初始化,存在并发安全性问题? #1108

Closed
wqmain opened this issue Aug 1, 2016 · 13 comments
Closed

1.r.57 IocBean初始化,存在并发安全性问题? #1108

wqmain opened this issue Aug 1, 2016 · 13 comments
Assignees
Milestone

Comments

@wqmain
Copy link

wqmain commented Aug 1, 2016

首先我是从1.b.52直接升级到1.r.57版本出现问题的(注,又试过1.b.53版本没问题),描述如下:
Action中@Inject注入一个声明了@IocBean的Service,Action中有三个方法分别调用了该Service的业务方法,前台通过3个ajax分别且同时提交请求到后台Action这三个方法,第1个ajax请求,Service正常初始化,但第2、3个ajax请求,报NPE,控制台在方法中可以打印出来Service为null。代码结构类似:
`@IocBean
@at("/index")
public class IndexAction extends BaseAction {
@Inject
private IndexService indexService;

@At("/m1")
public void method_1() {
    indexService.m1(); //第1个到达的ajax请求,indexService正常初始化
}

@At("/m2")
public void method_2() {
    indexService.m2(); //第2个到达的ajax请求,indexService为null,报NPE
}

@At("/m3")
public void method_3() {
    indexService.m3(); //第3个到达的ajax请求,同样indexService为null,报NPE
}

}`

@wqmain wqmain changed the title 1.r.57 IocBean初始化问题 1.r.57 IocBean初始化问题,是否存在并发安全性问题? Aug 1, 2016
@wqmain wqmain changed the title 1.r.57 IocBean初始化问题,是否存在并发安全性问题? 1.r.57 IocBean初始化,存在并发安全性问题? Aug 1, 2016
@wendal
Copy link
Member

wendal commented Aug 1, 2016

@ansjsun 是不是之前那个修改的问题

@wendal
Copy link
Member

wendal commented Aug 1, 2016

可否给出请求时的日志, 更好的推测原因

@wendal
Copy link
Member

wendal commented Aug 1, 2016

1.r.57是根据name加锁, 仔细思考了一下, 不可行

  1. 多个bean交叉获取lock的情况下,死锁
  2. 创建op的过程加锁了,但创建对象的过程没有加锁

第一个问题无法解决,因为引用的bean无法直接推断, 按name解锁无法解决.
第二个问题, 将对象创建过程也置于锁之内可以解决

为了解决第一个问题, 必须还原全局锁

@wendal
Copy link
Member

wendal commented Aug 1, 2016

@ansjsun 有无更好的解决办法?

@wqmain 请测试1.r.56或在MainSetup.init方法内添加如下代码临时解决

        for (String name : ioc.getNames()) {
            try {
                if (name.endsWith("Module") || name.endsWith("Action")) {
                    ioc.get(Object.class, name);
                }
            } catch (Throwable e) {
            }
        }

@wendal
Copy link
Member

wendal commented Aug 1, 2016

出错的过程是这样:

  1. A线程进入NutIoc.get, op还不存在于context, 根据name得到的锁
  2. A线程通过ObjectMaker生成ObjectProxy. 其中, 会把未完成的op对象放入上下文
  3. B线程进入NutIoc.get, op存在于context, 没有加锁, 直接调用op.get, 得到未组装完成的对象
  4. B线程获取对象, 但该对象尚未组装完成, 导致需要注入的属性为null, 触发NPE
  5. A线程完成组装,此时对象完整, 执行操作是正常的.

@ansjsun
Copy link
Contributor

ansjsun commented Aug 1, 2016

不好意思..这个bug有点大了...ioc过程的确得全局锁..应该是 @wendal 改的上一个版本...是好的...当时考虑不完全...

@wqmain
Copy link
Author

wqmain commented Aug 2, 2016

我是从1.b.52直接升级过去的,不用临时解决,暂不升级即可,另外1.b.53没有问题。
@wendal 需要我测试1.r.56吗?

@wqmain
Copy link
Author

wqmain commented Aug 2, 2016

@wendal @ansjsun 1.b.52换成1.r.56 ,系统跑不起来,我之前提的 #1066 issue只在1.r.57中体现了,1.r.56版本中没有修复.......

@wendal wendal closed this as completed in 3640cc8 Aug 2, 2016
@wendal
Copy link
Member

wendal commented Aug 2, 2016

@wqmain 麻烦你稍后试一下快照版,如果一切ok的话,我发布个1.r.57.r3

@wqmain
Copy link
Author

wqmain commented Aug 2, 2016

@wendal 不麻烦,快照版本是这个么?http://downloads.nutzam.com/get/276c5ab230b919eff2a9288496b4c725

@wendal
Copy link
Member

wendal commented Aug 2, 2016

@wqmain
Copy link
Author

wqmain commented Aug 2, 2016

@wendal 兽总,快照版本没有问题了。

@wendal
Copy link
Member

wendal commented Aug 2, 2016

@wqmain ok,我下午或晚上发布个1.r.57.r3

@wendal wendal added this to the 1.r.58 milestone Aug 2, 2016
@wendal wendal self-assigned this Aug 2, 2016
Wizzercn added a commit to Wizzercn/NutzWk that referenced this issue Aug 2, 2016
andrey-lazarevx added a commit to andrey-lazarevx/BoLaMNn that referenced this issue Apr 22, 2022
ma496781333c added a commit to ma496781333c/originallyus that referenced this issue Apr 22, 2022
hiperbolt9 added a commit to hiperbolt9/MortenSchenkb that referenced this issue Apr 22, 2022
Yacwamyunuanm added a commit to Yacwamyunuanm/lewang that referenced this issue Apr 23, 2022
MonsterDOGzp added a commit to MonsterDOGzp/chrislim2888 that referenced this issue Apr 23, 2022
Zeniten2 added a commit to Zeniten2/iTXTechl that referenced this issue Apr 23, 2022
jwhy89d added a commit to jwhy89d/loresoftf that referenced this issue Apr 23, 2022
AudunVN1 added a commit to AudunVN1/parc-ccnx-archiveh that referenced this issue Apr 23, 2022
fabrizzio-gzb added a commit to fabrizzio-gzb/DingHanyang9 that referenced this issue Apr 23, 2022
zhangzujian6 added a commit to zhangzujian6/GleasonK4 that referenced this issue Apr 23, 2022
tspringky added a commit to tspringky/bizz84s that referenced this issue Apr 23, 2022
JohnDDuncanIIIj added a commit to JohnDDuncanIIIj/ory that referenced this issue Apr 23, 2022
ffinlyo added a commit to ffinlyo/ReptarKb that referenced this issue Apr 23, 2022
authsolu added a commit to authsolu/NYAN-x-CATy that referenced this issue Apr 23, 2022
authsolu added a commit to authsolu/NYAN-x-CATy that referenced this issue Apr 23, 2022
dream7983 added a commit to dream7983/lowRISCl that referenced this issue Apr 23, 2022
MarynaPRa added a commit to MarynaPRa/log4cplusq that referenced this issue Apr 24, 2022
libcgr added a commit to libcgr/alanshawb that referenced this issue Apr 24, 2022
leeokdkpvv5c added a commit to leeokdkpvv5c/volevol9 that referenced this issue Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants