GithubHelp home page GithubHelp logo

Comments (4)

tohagan avatar tohagan commented on April 28, 2024 1

Having conditional logic as you've described to filter triggers does not prevent this kind of bug. Adding a condition may help you fix it but it won't detect or prevent it. The problem is that just looking at the Event Triggers (and their conditions) it's not obvious that the loop even exists. That's because the programmer is only seeing the 1st part of the loop code. The 2nd part is buried in the logic of the serverless function that performs a database update that then fires a new Event trigger. This kind of distributed execution path is inherently non-obvious as the programmer can easily miss seeing the complete call graph because the "code" is split between the two systems. The programmer is also likely to only unit test the function logic (possibly even stubbing database updates) and thus may miss detecting the distributed event loop.

A safe solution needs to behave similar to the way that a compiler/interpreter runtime or CPU hardware detects "stack overflow" except in our case the "calls" are distributed. To detect and prevent this you need a generic method (ideally supported by the framework) that computes the nested call depth between distributed execution threads. That's the solution I've proposed above. Identifying distributed threads has many other diagnostic benefits especially for long running (workflow) processes.

I can think of one case where an infinite distributed loop is ok. That's where we setup a chain of calls (events) with a computed delay performed by the serverless function between each event. Of course commonly we'd use a scheduled trigger (cron) for this but sometimes the delay intervals between these scheduled call need to be computed each time with hand crafted code. So to cater for this scenario, you'd need to ensure that the call depth check is optional.

from 3factor-example.

tohagan avatar tohagan commented on April 28, 2024

One solution comes to mind ...

  • Create command events with thread_id = request_id and thread_level = 0.
  • Business logic functions that execute command events create new events using the original thread_id and with thread_level = thread_level + 1 and of course a new request_id.
  • Function middleware can check if a command event includes thread_level and abort if it exceeds a threshold value (max event depth).
  • thread_id can be used in any diagnostics or reporting that requires event correlation including long running workflows, scheduled events, concurrent events etc.

from 3factor-example.

tohagan avatar tohagan commented on April 28, 2024

Event threading is an old trick but you might consider it worth documenting as part of 3 factor examples or perhaps even supporting in the framework.

Here's the backstory that you've probably already read.

from 3factor-example.

tirumaraiselvan avatar tirumaraiselvan commented on April 28, 2024

Great question!

I can tell you how you can address this in Hasura GraphQL Engine.

With Hasura Event Triggers, what you can do is choose the type of operation (INSERT, UPDATE, DELETE) and also choose the "LISTEN" columns for updates: https://hasura.io/docs/1.0/graphql/core/event-triggers/create-trigger.html#listen-columns-for-update

We are also planning conditional triggers: hasura/graphql-engine#1241 which will invoke a function only if some boolean expression (on the old or new row) is satisfied.

from 3factor-example.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.