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

StateMachine get blocked on 'aquireStateMachine(id)' when using an id that contains special regex characters #1115

Open
mirela-solomon opened this issue Sep 27, 2023 · 1 comment
Labels
status/need-triage Team needs to triage and take a first look

Comments

@mirela-solomon
Copy link

Hi,

I've encountered the following problem on spring-statemachine version 3.2.0.

We have the following configuration:

@Configuration
@EnableStateMachine
public class TicketStateMachineConfiguration {

    @Bean
    public StateMachineService<TicketStatus, TicketTrigger> stateMachineService(
            StateMachineFactory<TicketStatus, TicketTrigger> stateMachineFactory,
            StateMachinePersist<TicketStatus, TicketTrigger, String> stateMachinePersister) {
        return new DefaultStateMachineService<>(stateMachineFactory, stateMachinePersister);
    }

    @Configuration
    @EnableStateMachineFactory
    public static class TicketStateMachine extends StateMachineConfigurerAdapter<TicketStatus, TicketTrigger> {

        @Autowired
        private Collection<TicketStateConfiguration> stateConfigurations;

        @Autowired
        private StateMachineRuntimePersister<TicketStatus, TicketTrigger, String> runtimePersister;

        @Override
        public void configure(StateMachineConfigurationConfigurer<TicketStatus, TicketTrigger> config) throws Exception {
            config.withConfiguration().regionExecutionPolicy(RegionExecutionPolicy.PARALLEL);
            config.withPersistence().runtimePersister(runtimePersister);
        }

        @Override
        public void configure(StateMachineStateConfigurer<TicketStatus, TicketTrigger> states) throws Exception {
            states.withStates()
                    .initial(TicketStatus.LAUNCHING)
      		    .choice(...
      		    ...	
                    .states(EnumSet.allOf(TicketStatus.class));

            for (TicketStateConfiguration stateConfiguration : stateConfigurations) {
                stateConfiguration.configure(states);
            }
        }

        @Override
        public void configure(StateMachineTransitionConfigurer<TicketStatus, TicketTrigger> transitions) throws Exception {
            for (TicketStateConfiguration stateConfiguration : stateConfigurations) {
                stateConfiguration.configure(transitions);
            }
        }
    }
}

From the service we are trying to do:
StateMachine<S, E> stateMachine = stateMachineService.acquireStateMachine(id);

When providing an id that contains special regex characters like: "stateMachineService.acquireStateMachine("${ticketId}"), the state machine instance get blocked and is completely unusable. PatternSyntaxException are logged from the StateMachineObjectSupport methods but no exception is thrown and we are not able to get a response from acquireStateMachine method.

I tried to acquire the stateMachine and then manually start the machine, but I'm not able to get the errors from startup and not able to treat this scenario.

 StateMachine<S, E> stateMachine = stateMachineService.acquireStateMachine(id, false);
 stateMachine.startReactively().block();

I'll attach the debug logs for this issue:
logs_state-machine.txt

@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Sep 27, 2023
@relyativus
Copy link

relyativus commented Dec 17, 2023

We're also getting this on 4.0.0. Using UUID's as state machine identifier. It complains about dash, since it's interpreted as regex special character:
java.util.regex.PatternSyntaxException: Illegal character range near index 10 [6b7d358e-de78-4c80-ad8f-af33a2f3da09|15] ^ at java.base/java.util.regex.Pattern.error(Pattern.java:2028) at java.base/java.util.regex.Pattern.range(Pattern.java:2820) at java.base/java.util.regex.Pattern.clazz(Pattern.java:2708) at java.base/java.util.regex.Pattern.sequence(Pattern.java:2139) at java.base/java.util.regex.Pattern.expr(Pattern.java:2069) at java.base/java.util.regex.Pattern.compile(Pattern.java:1783) at java.base/java.util.regex.Pattern.<init>(Pattern.java:1430) at java.base/java.util.regex.Pattern.compile(Pattern.java:1069) at java.base/java.lang.String.replaceFirst(String.java:2898) at org.springframework.statemachine.processor.StateMachineHandlerCallHelper.getCacheEntries(StateMachineHandlerCallHelper.java:356) ...

full_stacktrace.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-triage Team needs to triage and take a first look
Projects
None yet
Development

No branches or pull requests

2 participants