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

Grakkit's JavaScript ticker (chain) can fail and does not resume #42

Open
MercerK opened this issue Mar 9, 2023 · 1 comment
Open
Labels
bug Something isn't working

Comments

@MercerK
Copy link
Contributor

MercerK commented Mar 9, 2023

I ran into an issue with setTimeout / setImmediate not working. After a lot of investigation, I narrowed it down to chain and instance.tick.

When the bug occurs, session.task.tick will stop accumulating and will always be stuck. When that happens, the JS's ticker will not trigger again until you do a reboot of the server.

My theory is that this may be due to a race condition between the Java/JS/Graal layers. I'm thinking that if a tick takes longer than a regular Java tick, it tries to call JavaScript's tick and nothing happens. When nothing happens, well, it gets released. Since it is released, it does not get readded (as it wasn't called/executed), thus, It doesn't know to tick it again. This seems like a major flaw.

I added a temporary hook in the library for troubleshooting

let thisNext
chain(void 0, (none, next) => {
  thisNext = next
  ....
 }

export const restartTick = () => {
  Grakkit.push(thisNext)
}

and was able to trigger restartTick by a command. When that happened, the ticker immediately start ticking again. However, that isn't a valid solution.

@MercerK MercerK added the bug Something isn't working label Mar 9, 2023
@MercerK
Copy link
Contributor Author

MercerK commented Mar 12, 2023

Since Grakkit leverages runTaskLater, it makes an attempt to call the function on that task. If that task fails, then the ticker fails hard. This doesn't seem to be a fault on the JavaScript side and I don't see a bug on the Grakkit side. It seems more of an issue between the two layers. Assuming that is the case, we should document this and build around the bug to avoid it as much as possible.

However, for this scenario, we may be able to mitigate it by:

  • Add a new method with Instance/GrakkitApi to register a ticker function. This is permanent and gets added to the tick.
  • Update Stdlib to register a ticker, versus leveraging Grakkit.push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant