Simulate throws 500 error on recursive rules

Bug #1565176 reported by Tim Hinrichs
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
congress
Triaged
High
Unassigned

Bug Description

When we try adding recursive rules during simulate, we get an internal error.

 $ openstack congress policy simulate alpha 's(x)' 's+(x) :- s(x)' action --delta --trace
Internal server error (HTTP 500) (Request-ID: req-e28eef31-4430-449a-a412-c300ed378510)

If we're not careful here, the policy engine could enter an infinite loop.

Rated High so we know to at least look into the possibility of an infinite loop.

Might want to address this issue as part of the blueprint on adding modals to simulate.
https://blueprints.launchpad.net/congress/+spec/simulate-with-modals

Revision history for this message
Eric K (ekcs) wrote :
Download full text (3.8 KiB)

I ran some tests and it seems a recursion results in infinite recursive calls that end with run time error.

Here's a sample selected log:
RuntimeError: maximum recursion depth exceeded^M
Traceback (most recent call last):^M
^M
  File "/usr/local/lib/python2.7/dist-packages/oslo_messaging/rpc/server.py", line 155, in _process_incoming^M
    res = self.dispatcher.dispatch(message)^M
^M
  File "/usr/local/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 222, in dispatch^M
    return self._do_dispatch(endpoint, method, ctxt, args)^M
^M
  File "/usr/local/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 192, in _do_dispatch^M
    result = func(ctxt, **new_args)^M
^M
  File "/opt/stack/congress/congress/policy_engines/agnostic.py", line 22
20, in simulate^M
    delta, trace, as_list)
    File "/opt/stack/congress/congress/policy_engines/agnostic.py", line 820, in simulate^M
    action_theory, delta, trace, as_list)^M
^M
  File "/opt/stack/congress/congress/policy_engines/agnostic.py", line 1247, in _simulate_string^M
    delta, trace)^M
^M
  File "/opt/stack/congress/congress/policy_engines/agnostic.py", line 1296, in _simulate_obj^M
    result = set(th_object.select(query))^M
^M
  File "/opt/stack/congress/congress/datalog/topdown.py", line 129, in select^M
    find_all=find_all)^M
^M
  File "/opt/stack/congress/congress/datalog/topdown.py", line 230, in top_down_evaluation^M
     save=None)^M
^M
  File "/opt/stack/congress/congress/datalog/topdown.py", line 257, in top_down_abduction^M
    self._top_down_eval(context, caller)^M
^M
  File "/opt/stack/congress/congress/datalog/topdown.py", line 332, in _top_down_eval^M
    return self._top_down_truth(context, caller)^M
^M
  File "/opt/stack/congress/congress/datalog/topdown.py", line 435, in _top_down_truth^M
    return self._top_down_includes(context, caller)^M
^M
  File "/opt/stack/congress/congress/datalog/topdown.py", line 439, in _top_down_includes^M
    is_true = self._top_down_th(context, caller)^M
    File "/opt/stack/congress/congress/datalog/topdown.py", line 473, in _top_down_th^M
    if self._top_down_eval(new_context, caller):^M
^M
  File "/opt/stack/congress/congress/datalog/topdown.py", line 332, in _top_down_eval^M
    return self._top_down_truth(context, caller)^M
^M
  File "/opt/stack/congress/congress/datalog/topdown.py", line 435, in _top_down_truth^M
    return self._top_down_includes(context, caller)^M
^M
  File "/opt/stack/congress/congress/datalog/topdown.py", line 439, in _top_down_includes^M

There are at least three options for addressing this error:
1. Perform static analysis of the query+policy rules to know ahead of time it'd lead to infinite recursive calls. Reject query.
2. Check the call stack to terminate infinite recursive call early.
3. Catch the RuntimeError when recursive call limit reached, then give a meaningful error message to user.

Given that the problem occurs infrequently, I think 3 is acceptable.

---

Note that there may be more complex variants of this problem. For example:

$ openstack congress policy rule create alpha 'a(x) :- b(x)'
+---------+--------------------------------------+
| Field | Value ...

Read more...

Revision history for this message
Eric K (ekcs) wrote :

Pretty important to fix/contain this problem because it it leaves congress in a bad state after the failure. At the very least we need to catch the error and clean up the state.

$ openstack congress policy row list alpha s
Internal server error (HTTP 500) (Request-ID: req-46f9e5ed-8468-473b-abd4-9c8a8ef902f8)

Same kind of infinite recursive calls result likely because the temporarily added rule in simulate was not removed.

Changed in congress:
milestone: none → pike-2
Eric K (ekcs)
Changed in congress:
status: New → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.