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

infinite loop and OOM caused by wrong passedTime #53

Open
imsenyu opened this issue Jan 28, 2018 · 7 comments
Open

infinite loop and OOM caused by wrong passedTime #53

imsenyu opened this issue Jan 28, 2018 · 7 comments

Comments

@imsenyu
Copy link

imsenyu commented Jan 28, 2018

we found that js enter infinite loop and go into OutOfMemory soon when system time changed backward with dragonBoneesJS@5.0.0。And I will show the whole steps in master branch.

  1. passedTime got negative number when system time changed backward at WorldClock.ts#L106
  2. then, this.time -= passedTime made this.time become larger indeed ( subtracting a negative number means adding a positive number) at WorldClock.ts#L114
  3. after serveral ticks, this.time became a huge number such as 1e308
  4. and passedTime got a negative maximum after it is subtracted from the huge this.time in next tick at WorldClock.ts#L106
  5. then every IAnimatable instances got the wrong passedTime such as -1e308 at WorldClock#45
  6. after a series of process,
@imsenyu
Copy link
Author

imsenyu commented Jan 28, 2018

one solution is to fix incorrect modification of this.time when passedTime < 0.0. but the inner processing logic is not such robust that maybe other triggers/conditions can lead to same error.

@imsenyu
Copy link
Author

imsenyu commented Jan 28, 2018

for example:

// tick 1
this.time === 1000;
Date.now === 1100;
passedTime got 100;
this.time += 100;
this.time === 1100;

// change system time from 1100 to 900

// tick 2
this.time === 1100;
Date.now === 900;
passedTime got -200;
this.time -= -200;
this.time === 1300;

// tick 3
this.time === 1300;
Date.now === 901;
passedTime got -399;
this.time -= -399;
this.time === 1699;

// tick 4
this.time === 1699;
Date.now === 902;
passedTime got -796;
this.time -= -796;
this.time === 2495;

// tick N
this.time boom to Infinity
passedTime boom to -Infinity

@imsenyu
Copy link
Author

imsenyu commented Jan 28, 2018

I also found the same mistake exists in the implemention of CSharp and Java, but I have not debug into the inner processing logic and I am not sure whether it will lead to infinite loop.

csharp

java

but it is ok in the implemention of CPP...(it does not use this.time to calculate the time difference automatically although this.time is wrong )

@imsenyu
Copy link
Author

imsenyu commented Jan 28, 2018

thanks to @qingyangmoke 's commit fix/modifytime_2018_01_28

he fix same error when timeScale not equal to 1.0

here is PR commit 001c609

@akdcl
Copy link
Member

akdcl commented Jan 29, 2018

clock 内部的系统时间不应该是一个递减的值,我们期望时间应该始终向前流动,所以才尝试修正负向的流逝时间,但是完全没有考虑到因此可能带来的问题,感谢提供的例子信息,我们会尝试让这个地方的逻辑更合理 :)

@imsenyu
Copy link
Author

imsenyu commented Jan 29, 2018

回复及时啊:)

烦请关注/推动对应同事关注JavaCSharpCPP以及其他语言的对应实现问题,虽然其中CPP实现没导致坏掉。

@imsenyu imsenyu changed the title infinite loop and OOM caused by warong passedTime infinite loop and OOM caused by wrong passedTime Jan 29, 2018
@akdcl
Copy link
Member

akdcl commented Jan 29, 2018

一定会将其他语言的逻辑也都统一的,请放心:)

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

2 participants