Commons SCXML
  1. Commons SCXML
  2. SCXML-61

Infinite loop if an Invoker fires the done event in invoke method

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.6
    • Fix Version/s: 0.7
    • Labels:
      None
    • Environment:

      all platforms

      Description

      With the following code

      public class HazInvoker implements Invoker
      {
      @Override public void invoke(String source, Map parameters) throws InvokerException
      {
      System.out.println("Invoker invoke source: "source" params: "+parameters);
      SCXMLExecutor executor = scInstance.getExecutor();
      TriggerEvent event=new TriggerEvent(parentStateId+".invoker.done", TriggerEvent.SIGNAL_EVENT);

      //new AsyncTrigger(executor, event);
      try

      { executor.triggerEvent(event); }

      catch (ModelException ex)

      { ex.printStackTrace(); }

      }

      Exception in thread "main" java.lang.StackOverflowError
      at java.util.Vector.addElement(Vector.java:573)
      at java.util.Stack.push(Stack.java:50)
      ...
      at org.apache.commons.scxml.semantics.SCXMLSemanticsImpl.initiateInvokes(SCXMLSemanticsImpl.java:824)
      at org.apache.commons.scxml.SCXMLExecutor.triggerEvents(SCXMLExecutor.java:142)
      at org.apache.commons.scxml.SCXMLExecutor.triggerEvent(SCXMLExecutor.java:160)
      at com.hazlorealidad.fsm.HazInvoker.invoke(HazInvoker.java:37)
      at org.apache.commons.scxml.semantics.SCXMLSemanticsImpl.initiateInvokes(SCXMLSemanticsImpl.java:824)
      at org.apache.commons.scxml.SCXMLExecutor.triggerEvents(SCXMLExecutor.java:142)
      at org.apache.commons.scxml.SCXMLExecutor.triggerEvent(SCXMLExecutor.java:160)
      at com.hazlorealidad.fsm.HazInvoker.invoke(HazInvoker.java:37)

      The fix is to use the AsyncTrigger but the class is package private, I would be good to change it to public and document the way to write a synchronous invoker in the invoke method.

      Something like:
      "If the Invoker completes its invocation in the invoke method it should signal the completion of the task using an AsyncTrigger, in order to avoid a stack overflow"

      Or maybe there is another solution which would allow the event to be fired in the invoke method.

      Also it would be good to avoid the creation of a thread just for that, maybe an invokeLater method in the executor, like the swing dispatch loop.

        Activity

        Hide
        Rahul Akolkar added a comment -

        This will be fixed in v0.7 only to the effect of adding explicit Javadoc enhancements as you suggest.

        Invoke has necessarily asynchronous semantics, and tends toward long(er) running interaction semantics. For synchronous interactions, custom actions (executable content) are more appropriate. AsyncTrigger was left out of the public API by design (as you indicate, it may not please everyone).

        Show
        Rahul Akolkar added a comment - This will be fixed in v0.7 only to the effect of adding explicit Javadoc enhancements as you suggest. Invoke has necessarily asynchronous semantics, and tends toward long(er) running interaction semantics. For synchronous interactions, custom actions (executable content) are more appropriate. AsyncTrigger was left out of the public API by design (as you indicate, it may not please everyone).
        Hide
        Rahul Akolkar added a comment -

        Added Javadoc clarification per previous comment.

        Show
        Rahul Akolkar added a comment - Added Javadoc clarification per previous comment.

          People

          • Assignee:
            Unassigned
            Reporter:
            Andy Bailey
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development