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

Race condition upon the instantiation of declarative state machines #140

Open
mr-khabib opened this issue Dec 1, 2022 · 0 comments
Open

Comments

@mr-khabib
Copy link

Periodically I'm getting ConcurrentModificationException/IllegalStateException while using Declarative fsm's.

I was able to partially reproduce with this UT:

@Test
    public void testRaceForUntypedStateMachine() {
        final CountDownLatch eventCondition = new CountDownLatch(5);
        StateMachineBuilder<DeclarativeStateMachine, TestState, TestEvent, Integer> bmyBuilder =
                StateMachineBuilderFactory.<DeclarativeStateMachine, TestState, TestEvent, Integer>
                        create(DeclarativeStateMachineImpl.class, TestState.class,
                        TestEvent.class, Integer.class, DeclarativeStateMachine.class);
        Thread thr1 = new Thread(new Runnable() {
            @Override
            public void run() {
                while(true) {
                    DeclarativeStateMachine fsm1 = bmyBuilder.newStateMachine(TestState.A, monitor);
                    fsm1.fire(TestEvent.InternalA, null);
                }
            }
        }, "Test-Thread-1");

        Thread thr2 = new Thread(new Runnable() {
            @Override
            public void run() {
                while(true) {
                    DeclarativeStateMachine fsm2 = bmyBuilder.newStateMachine(TestState.A, monitor);
                    fsm2.fire(TestEvent.InternalA, null);
                }

            }
        }, "Test-Thread-2");

        try {
            thr1.start();
            thr2.start();
            eventCondition.await(2, TimeUnit.SECONDS);
            TimeUnit.MILLISECONDS.sleep(100);
        } catch (InterruptedException e) {
            fail();
        }
    }

Issue reproduce in unpredictable manner - some time every run of this test, some time it needed to be run 10 times to get this state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant