Core: Processes seem to be able to kill themselves

Created on 27 May 2016  路  11Comments  路  Source: elm/core

@alphalambda made a http://sscce.org/ in which you can trigger a runtime error if you click Pause and Resume a bunch of times.

https://gist.github.com/alphalambda/448099e95858b0ffc91fd41fdb1b437a

Looking at where the error happens, it seems that the currently running process is killed _while_ it is running. This suggests to me that the process is somehow killing itself. I don't know how that can be possible.

Update: @jagare says

there are messages for the kill process left in the workerQueue

Suggesting that kill either needs to clear the messages to that node, or that there's some check needed when you start handling a node that isn't there already.

bug

Most helpful comment

I just ran into the same issue when trying to stop AnimationFrame. I need this to suspend a game, so that then it can be restored by a message from a port.

UPD: currently I'm patching generated elm.js in the way suggested by @jagare and it seems to be working.

All 11 comments

A workaround that stops the crashes is to change line 132 in src/Native/Scheduler.js from
while (numSteps < MAX_STEPS)
into
while (numSteps < MAX_STEPS && process.root)

I don't think the process is killing itself.
From what I can see in the debugger the process is killed from here:
https://github.com/elm-lang/animation-frame/blob/1.0.0/src/AnimationFrame.elm#L84
But it is not done from the process when it is running!
In my case, adding a few logs, the process with id 840 was killed by pid 3. However there where still a message for pid 840 in the workQueue. In fact after killing pid 840, pid 0 and pid 3 processed one message each before pid 840 was to process a message after it has been killed, which results in the exception.
So it appears to me as if the problem is that the problem comes from that there are messages for the kill process left in the workerQueue. I guess one solution can be to just replace

numSteps = step(numSteps, process);
with
if (process.root) { numSteps = step(numSteps, process); }
Since we want to continue processing the rest of the messages in the workQueue.

I just ran into the same issue when trying to stop AnimationFrame. I need this to suspend a game, so that then it can be restored by a message from a port.

UPD: currently I'm patching generated elm.js in the way suggested by @jagare and it seems to be working.

Similar issue (though with subscriptions being turned on/off) at: https://github.com/elm-lang/animation-frame/issues/7

I think @jagare has the right idea for the fix. I'll look into it a bit more now.

Can people check if https://github.com/elm-lang/core/commit/9320969bf47082b902d4511ef8a48a93612d7bf0 fixes it for them?

If so, I'll do a patch release. Thanks again @jagare!

That is precisely what I've been doing to my generated javascript (prior to finding this issue, would have saved me time if I'd found it before...) and it works, and based on that processes can be killed it looks like the right thing to do too. I'd love a patch release! ^.^

Cool, thanks for confirming this. I'll do a bit more testing myself and then do a patch.

Okay, core 4.0.4 should be out. Thanks again to everyone who helped sort this out!

Upgraded, tried my code at work as well as tests and all passed without me needing to mess with the output javascript. Thanks much! ^.^

Thanks!

Was this page helpful?
0 / 5 - 0 ratings