azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

azure.communication.email.EmailClient send method not throwing error if response status code is 429

Open gvnn opened this issue 3 years ago • 4 comments

  • Package Name: azure-communication-email
  • Package Version: 1.0.0b1
  • Operating System: Linux
  • Python Version: 3.8

Describe the bug When calling send method of EmailClient and rate limiting (Response status 429) has been reached, script hangs and doesn't throw an error.

To Reproduce Steps to reproduce the behavior:

  1. Create a little script to call the send method. e.g.
from azure.communication.email import EmailClient, EmailContent, EmailAddress, EmailMessage, EmailRecipients

connection_string = "..."
client = EmailClient.from_connection_string(connection_string);

content = EmailContent(
    subject="This is the subject",
    plain_text="This is the body",
    html= "<html><h1>This is the body</h1></html>",
)

address = EmailAddress(email="...")

message = EmailMessage(
    sender="...",
    content=content,
    recipients=EmailRecipients(to=[address])
)

response = client.send(message)
  1. Repeat it more than 25 times in a hour (Communication service rate limit)
  2. Execute it a 26th time
  3. ... Process hangs

Expected behavior Throw exception so can be caught and processed accordingly

Screenshots Below an example of a Azure Function that receives a 429 immediately, but times out after 5 minutes because no exception has been raised.

Untitled

Additional context In our specific case this function is triggered by a Servicebus message. If I had the possibility to catch the exception and the Retry-After value I could potentially re-schedule the message. I have noticed that the library offers a cls parameter that could be used to pass also the Retry-After and not only x-ms-request-id.

gvnn avatar Sep 08 '22 08:09 gvnn

Thanks for the feedback @gvnn, we'll investigate asap. cc @turalf

kashifkhan avatar Sep 08 '22 13:09 kashifkhan

Thank you for your feedback. This has been routed to the support team for assistance.

ghost avatar Sep 08 '22 13:09 ghost

After a bit of debugging we've found a solution to our problem, using a no retry policy.

e.g.

from azure.core.pipeline.policies import RetryPolicy

connection_string = "..."
client = EmailClient.from_connection_string(
    connection_string, retry_policy=RetryPolicy.no_retries()
)

This because the email client uses PipelineClient and arguments trickle down to that class and it accept a policy with no retries.

Maybe this could be pointed out in the readme of the lib?

Thanks for looking into this.

G.

gvnn avatar Sep 09 '22 00:09 gvnn

Hi @gvnn. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

ghost avatar Sep 23 '22 16:09 ghost

@xiangyan99 - I'm not sure this should be marked as addressed. We should not have to resort to changing the retry policy for the correct behaviour - I think the service team needs to address this.

annatisch avatar Sep 26 '22 19:09 annatisch

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @acsdevx-msft.

Issue Details
  • Package Name: azure-communication-email
  • Package Version: 1.0.0b1
  • Operating System: Linux
  • Python Version: 3.8

Describe the bug When calling send method of EmailClient and rate limiting (Response status 429) has been reached, script hangs and doesn't throw an error.

To Reproduce Steps to reproduce the behavior:

  1. Create a little script to call the send method. e.g.
from azure.communication.email import EmailClient, EmailContent, EmailAddress, EmailMessage, EmailRecipients

connection_string = "..."
client = EmailClient.from_connection_string(connection_string);

content = EmailContent(
    subject="This is the subject",
    plain_text="This is the body",
    html= "<html><h1>This is the body</h1></html>",
)

address = EmailAddress(email="...")

message = EmailMessage(
    sender="...",
    content=content,
    recipients=EmailRecipients(to=[address])
)

response = client.send(message)
  1. Repeat it more than 25 times in a hour (Communication service rate limit)
  2. Execute it a 26th time
  3. ... Process hangs

Expected behavior Throw exception so can be caught and processed accordingly

Screenshots Below an example of a Azure Function that receives a 429 immediately, but times out after 5 minutes because no exception has been raised.

Untitled

Additional context In our specific case this function is triggered by a Servicebus message. If I had the possibility to catch the exception and the Retry-After value I could potentially re-schedule the message. I have noticed that the library offers a cls parameter that could be used to pass also the Retry-After and not only x-ms-request-id.

Author: gvnn
Assignees: -
Labels:

question, Service Attention, Client, customer-reported, Communication

Milestone: -

ghost avatar Oct 28 '22 02:10 ghost

Adding Service team to look into this.

@acsdevx-msft Could you please look into this once you get a chance ?

navba-MSFT avatar Oct 28 '22 02:10 navba-MSFT