Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.36k stars 2k forks source link

Improve logic to avoid block call under non blocking thread #43063

Closed moarychan closed 14 hours ago

moarychan commented 19 hours ago

Description

Cherry-pick from https://github.com/Azure/azure-sdk-for-java/pull/40772

Issues #12500, #35845 and #35215 appear to be due to EventHubsTemplate.doSend performing a block() call. When used by the non-async methods in EventHubsTemplate, or the async methods when a non-parallel Reactor Scheduler is being used, this will work well enough. But when using a parallel Reactor Scheduler, blocking calls are prohibited.

This PR restructures the code in EventHubsTemplate.doSend to not use a blocking call. A test was added first to verify that we could detect this condition by performing one of the existing test cases with Scheduler.parallel(). After the changes to EventHubsTemplate, this test passes.

And fix the same issue for DefaultMessageHandler.handleMessageInternal.

All SDK Contribution checklist:

General Guidelines and Best Practices

Testing Guidelines

azure-sdk commented 19 hours ago

API change check

API changes are not detected in this pull request.