Closed arturocuya closed 1 year ago
@arturocuya I think I found the issue. It seems to be related to the fact that we do not unobserve the state. I am going to submit a fix to our internal project today just to make sure we don't see regressions and can put it forward here next week if it looks good.
Before:
After:
I have set up a sample project for this issue, with the following:
start()
that returns the promise and starts the task. The main func resolves the promise.So something like this
I want to be able to press a button at any moment so that the "hello" task runs only after the 2 preconditions have been met.
I've tried the following approaches:
promise.all()
and usepromises.chain()
. This didn't work at all, so you won't see it included in the sample project.promise.all()
duringinit()
and reference it when the button is pressedonThen
s for each precondition and then for the task.The last 2 approaches work, the problem is that if you keep pressing the button, eventually the program crashes due to an execution time out. I've been able to identify that the function
promises.isPromise()
is somehow related to the problem. I put a print statement in that function to check how many times it's called and every time I press the button, the amount grows similarly to a fibonacci function.I also discovered that just calling the Task doesn't cause this problem, so maybe it's related to how I'm creating the promises and resolving them in the render thread instead of a task thread?
Similarly, calling just the preconditions also causes a growth in the number of calls to
promise.isPromise()
The way I'm testing the number of calls to
isPromise()
is by opening the app and waiting for the timers to end. At this point it's called around 25 times, which is constant across app resets. Then I start pressing the button and each time I see the number of calls grow (you have to clear the telnet console each time to see the number of prints for each press)m.preconditions
made frompromise.all()
->12, 13, 15, 19, 27, 43, 75, 139, 267, 523
=a(n) = a(n-1) + a(n-2) + 1
19, 23, 31, 47, 79, 143, 271, 527
=a(n) = a(n-1) + a(n-2) + 3
no growth! always 7 prints
5, 6, 8, 12, 20, 36, 68, 132, 260, 516
=a(n) = a(n-1) + a(n-2) + 2
The attached .zip contains the sample project with all of the approaches listed, ready to be uncommented and tested. You'll need to run
npm install
first because it usesbsc
.promises-mem-leak.zip
If you spam the button eventually you'll see this execution timeout crash.