Azure / azure-rest-api-specs-examples

SDK examples for azure-rest-api-specs
MIT License
22 stars 13 forks source link

Event Grid Manager hangs creating event topic subscription #2197

Open afrancoc2000 opened 1 year ago

afrancoc2000 commented 1 year ago

Library name and version

com.azure.resourcemanager:azure-resourcemanager-eventgrid:1.2.0-beta.3

Sample Issue Type

Issue details

I'm trying to create a subscription using the EventGridManager, if the webhook endpoint for the destination is good everything works, but if the endpoint is not a valid webhook, the service hangs indefinitely. Is there a way to set a timeout? so that the service doesn't hangs, as right now I need to interrupt the thread.

Thanks

EventSubscription eventSubscription = manager.topicEventSubscriptions()
  .define(eventSubscriptionName)
  .withExistingTopic(resourceGroupName, eventGridTopicName)
  .withDestination(destination)
  .create();

Expected behavior

If the endpoint is not valid a timeout a default timeout happens and fails, and this timeout can be set from the create method.

Actual behavior

On wrong endpoint the thread hangs indefinitely

Reproduction Steps

Try to create a subscription using "www.microsoft.com" as endpoint

var url = URI.create("www.microsoft.com");
WebhookEventSubscriptionDestination destination = new WebhookEventSubscriptionDestination()
  .withEndpointUrl(url.toString());

EventSubscription eventSubscription = manager.topicEventSubscriptions()
  .define(eventSubscriptionName)
  .withExistingTopic(resourceGroupName, eventGridTopicName)
  .withDestination(destination)
  .create();

Environment

Java: 17 Windows 11 Maven 3.8.7 Intellij Idea 2021.3.3

weidongxu-microsoft commented 1 year ago

@XiaofeiCao feel free to move the azure-sdk-for-java repo

I think author asks how to abort/timeout a LRO. Note this is Lite lib, we don't have async API there.


As fallback, one can do this

            SyncPoller<PollResult<?>, EventSubscriptionInner> poller =
                eventGridManager.serviceClient().getTopicEventSubscriptions()
                    .beginCreateOrUpdate(...);
            PollResponse<PollResult<?>> lastResponse = poller.waitForCompletion(Duration.ofMinutes(10));
            if (lastResponse.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
                // succeeded
                EventSubscriptionInner result = poller.getFinalResult();
            } else {
                // failed or not completed in time
            }