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

Downloading Attachment requires delay #2207

Closed
grippstick opened this issue Nov 10, 2023 · 4 comments
Closed

Downloading Attachment requires delay #2207

grippstick opened this issue Nov 10, 2023 · 4 comments

Comments

@grippstick
Copy link

After receiving a Subscription notification that an Email has been created. I check to see if the email has attachments. If it does, I attempt to download the attachments.
I will initially get the following exception:

Exception Type: Microsoft.Graph.ServiceException
Error: Code: ErrorItemNotFound
Message: The specified object was not found in the store., The store ID provided isn't an ID of an item.

If I repeatedly retry to download the attachments, it will eventually succeed after 4-5 minutes.

To Reproduce

  1. Get Message and Attachment List
    var msg = await graphClient.Me.Messages[MicrosoftId]
    .Request()
    .WithImmutableId()
    .Expand(EXPAND_MIME_HEADERS) .Select("internetMessageId,internetMessageHeaders,createdDateTime,subject,bodyPreview,hasAttachments,uniqueBody,body,from,toRecipients,ccRecipients,bccRecipients,isDraft")
    .GetAsync()
    .ConfigureAwait(false);

var atts = await graphClient.Me.Messages[MicrosoftId].Attachments
.Request()
.WithImmutableId()
.Select("id,name,size,isInline,contentType,microsoft.graph.fileAttachment/contentId")
.GetAsync(cancelAttachments.Token)
.ConfigureAwait(false);

foreach(var att in atts){
//Fails with above error
//failure is intermittent
var attMS = await graphClient.Me
.Messages[msg.Id]
.Attachments[att.Id]
.Request()
.WithImmutableId()
.GetAsync()
.ConfigureAwait(false) as FileAttachment;
}

I expect attachments to download.......

@andrueastman
Copy link
Member

Thanks for raising this @grippstick

From the error description it looks like the API would occasionally need sometime before the attachment is available for download. As this is an API related issue, and this repo is mainly intended for issues related to the SDK, any chance you can create a ticket/question at the link below to get feedback from the API owners if this is expected from the API and whether there is an expected timeout before making the subsequent request?

https://developer.microsoft.com/en-us/graph/support

@grippstick
Copy link
Author

grippstick commented Nov 14, 2023 via email

@andrueastman
Copy link
Member

Thanks for confirming @grippstick

The SDK by default does implement retry mechanisms based on the API guidance at https://learn.microsoft.com/en-us/graph/best-practices-concept#handling-expected-errors for 502,503 and 429 errors.

Unfortunately, for a 404 error, it gets tricky to really know if the item does not really exist or hasn't been provisioned yet as in your scenario. One thing you could do though is pass custom retry options to the retry handler for the request so that is caters for 404 response.

            var attMS = await graphClient.Me
                                    .Messages["massage-id"]
                                    .Attachments["attachement-id"]
                                    .Request()
                                    .WithShouldRetry((delay, attempt, response) =>
                                    {
                                        if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                                            return true; // retry for 404 for this request.

                                        return false;
                                    })
                                    .WithMaxRetry(3)// max retry of 3
                                    .GetAsync()
                                    .ConfigureAwait(false) as FileAttachment;

Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants