camunda / camunda-bpm-platform

Flexible framework for workflow and decision automation with BPMN and DMN. Integration with Quarkus, Spring, Spring Boot, CDI.
https://camunda.com/
Apache License 2.0
4.1k stars 1.55k forks source link

Creating client without subscribing to a topic causes infinite loop #2337

Open ThorbenLindhauer opened 4 years ago

ThorbenLindhauer commented 4 years ago

This issue was imported from JIRA:

Field Value
JIRA Link CAM-11908
Reporter @nevries
Has restricted visibility comments false

What are the steps to reproduce your problem?

Just try that:

public static void main(String[] args) throws InterruptedException {
    ExternalTaskClient client = ExternalTaskClient.create()
        .baseUrl("http://localhost:8080/engine-rest")
        .asyncResponseTimeout(1000)
        .build();

    Thread.sleep(300_000);
}

What is the problem?

CPU usage goes to 100% (for one thread).

What would be the expected behavior:

Keep calm and wait for subscription.

Hints (optional):

This goes wild: camunda-external-task-client-java/client/src/main/java/org/camunda/bpm/client/topic/impl/TopicSubscriptionManager.java

Links:

ThorbenLindhauer commented 4 years ago

This comment was imported from JIRA and written by user @koevskinikola


Hey @nevries,

Thank you for the report. Is there a stack trace or any logs that you can provide for the error, or the only indicator is the CPU usage?

Best, Nikola

ThorbenLindhauer commented 4 years ago

This comment was imported from JIRA and written by user @nevries


Hi @koevskinikola,

sorry, no stack trace, because I stopped investigating after having a look at these lines of code: https://github.com/camunda/camunda-external-task-client-java/blob/11a7fcf44e11375d85759494e20f25641fcff3e0/client/src/main/java/org/camunda/bpm/client/topic/impl/TopicSubscriptionManager.java#L84-L119

For me it was pretty clear that, given subscriptions being an empty collection, there is an infinite loop. Actually, having a second look, it seems also the case if isBackoffStrategyDisabled is true. But maybe I was jumping to the conclusions. What I definitely can tell is: Just observing the CPU load, after passing a code line that does a topic subscription, the CPU usage goes immediately back to normal.

ThorbenLindhauer commented 4 years ago

This comment was imported from JIRA and written by user @koevskinikola


Hey @nevries,

I managed to reproduce the issue. At least half of my CPU cores were constantly at 100%. I'll forward the ticket for scheduling.

The load is the same no matter if the Backoff strategy is disabled or enabled.

Best, Nikola

ThorbenLindhauer commented 4 years ago

This comment was imported from JIRA and written by user @nevries


{quote}The load is the same no matter if the Backoff strategy is disabled or enabled. {quote} What I meant is: Even if you have at least one subscription, I expect the problem to appear also if backoff strategy is disabled. I did not test that, but if my assumption about the root cause of the problem is correct, it would imply that behavior as well.

ThorbenLindhauer commented 4 years ago

This comment was imported from JIRA and written by user @ThorbenLindhauer


Hey Ragnar,

I won't schedule a fix for the time being due to other priorities. Feel free to raise a support case if you need a fix until a certain deadline.

Cheers, Thorben

adisin17 commented 4 months ago

Hi @ThorbenLindhauer, I would like to work on this issue. Can I pick this up?

yanavasileva commented 4 months ago

@adisin17, feel free to raise a pull request for this and don't forget to add the ticket's number. Code has been moved and now it can be found here: https://github.com/camunda/camunda-bpm-platform/tree/master/clients/java

adisin17 commented 4 months ago

Sure, I'll start the work. Thanks!