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

BatchRequestContent doesn't work with big messages #2701

Closed
Rabbit2004Liza opened this issue Oct 7, 2024 · 2 comments
Closed

BatchRequestContent doesn't work with big messages #2701

Rabbit2004Liza opened this issue Oct 7, 2024 · 2 comments
Labels

Comments

@Rabbit2004Liza
Copy link

Describe the bug

I am trying to send batch of messages using ms graph.

I tried to execute this code and it worked correctly.

public static void main(String[] args) throws IOException
{
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId("xxx")
.clientSecret("xxx")
.tenantId("xxx")
.build();
GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential,"https://graph.microsoft.com/.default");
BatchRequestContent batchRequestContent = new BatchRequestContent(graphServiceClient);

    Message message1 = new Message();
    message1.setSubject("sub1");

    ItemBody body1 = new ItemBody();
    body1.setContentType(BodyType.Text);
    body1.setContent( "body1");
    message1.setBody(body1);

    Recipient recipient1 = new Recipient();
    EmailAddress emailAddress1 = new EmailAddress();
    emailAddress1.setAddress("xxx@gmail.com");
    recipient1.setEmailAddress(emailAddress1);

    message1.setToRecipients(List.of(recipient1));

    SendMailPostRequestBody sendMailPostRequestBody1 = new SendMailPostRequestBody();
    sendMailPostRequestBody1.setMessage(message1);

    RequestInformation requestInformation1 =
            graphServiceClient.users()
                    .byUserId("xxx")
                    .sendMail()
                    .toPostRequestInformation(sendMailPostRequestBody1);

    batchRequestContent.addBatchRequestStep(requestInformation1);


    Message message2 = new Message();
    message2.setSubject("sub2");

    ItemBody body2 = new ItemBody();
    body2.setContentType(BodyType.Text);
    body2.setContent("body2");
    message2.setBody(body2);

    Recipient recipient2 = new Recipient();
    EmailAddress emailAddress2 = new EmailAddress();
    emailAddress2.setAddress("xxx@gmail.com");
    recipient2.setEmailAddress(emailAddress2);

    message2.setToRecipients(List.of(recipient2));

    SendMailPostRequestBody sendMailPostRequestBody2 = new SendMailPostRequestBody();
    sendMailPostRequestBody2.setMessage(message2);

    RequestInformation requestInformation2 =
            graphServiceClient.users()
                    .byUserId("xxx")
                    .sendMail()
                    .toPostRequestInformation(sendMailPostRequestBody2);

    batchRequestContent.addBatchRequestStep(requestInformation2);
    graphServiceClient.getBatchRequestBuilder().post(batchRequestContent, null);
    System.out.println("hello");
}

But than I added more symbols to message body and executed code again. It didn't print "hello" and recipient didn't get emails.
I tried to debug this case and found out that code execution is stucked in endless loop in PipedInputStream#awaitSpace.

What is the reason of such behavior ? Is there any way to fix it ?

This is the chunk of code which doesn't work. I just added more symbols to body1 and body2.

public static void main(String[] args) throws IOException
{
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId("xxx")
.clientSecret("xxx")
.tenantId("xxx")
.build();
GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential,"https://graph.microsoft.com/.default");
BatchRequestContent batchRequestContent = new BatchRequestContent(graphServiceClient);

    Message message1 = new Message();
    message1.setSubject("sub1");

    ItemBody body1 = new ItemBody();
    body1.setContentType(BodyType.Text);
    body1.setContent( "body1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
    message1.setBody(body1);

    Recipient recipient1 = new Recipient();
    EmailAddress emailAddress1 = new EmailAddress();
    emailAddress1.setAddress("xxx@gmail.com");
    recipient1.setEmailAddress(emailAddress1);

    message1.setToRecipients(List.of(recipient1));

    SendMailPostRequestBody sendMailPostRequestBody1 = new SendMailPostRequestBody();
    sendMailPostRequestBody1.setMessage(message1);

    RequestInformation requestInformation1 =
            graphServiceClient.users()
                    .byUserId("xxx")
                    .sendMail()
                    .toPostRequestInformation(sendMailPostRequestBody1);

    batchRequestContent.addBatchRequestStep(requestInformation1);


    Message message2 = new Message();
    message2.setSubject("sub2");

    ItemBody body2 = new ItemBody();
    body2.setContentType(BodyType.Text);
    body2.setContent("body2wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww");
    message2.setBody(body2);

    Recipient recipient2 = new Recipient();
    EmailAddress emailAddress2 = new EmailAddress();
    emailAddress2.setAddress("xxx@gmail.com");
    recipient2.setEmailAddress(emailAddress2);

    message2.setToRecipients(List.of(recipient2));

    SendMailPostRequestBody sendMailPostRequestBody2 = new SendMailPostRequestBody();
    sendMailPostRequestBody2.setMessage(message2);

    RequestInformation requestInformation2 =
            graphServiceClient.users()
                    .byUserId("xxx")
                    .sendMail()
                    .toPostRequestInformation(sendMailPostRequestBody2);

    batchRequestContent.addBatchRequestStep(requestInformation2);
    graphServiceClient.getBatchRequestBuilder().post(batchRequestContent, null);
    System.out.println("hello");
}

Expected behavior

I expect that this chunk of code will be executed correctly and two messages will be delivered to recipient.

public static void main(String[] args) throws IOException
{
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId("xxx")
.clientSecret("xxx")
.tenantId("xxx")
.build();
GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential,"https://graph.microsoft.com/.default");
BatchRequestContent batchRequestContent = new BatchRequestContent(graphServiceClient);

    Message message1 = new Message();
    message1.setSubject("sub1");

    ItemBody body1 = new ItemBody();
    body1.setContentType(BodyType.Text);
    body1.setContent( "body1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
    message1.setBody(body1);

    Recipient recipient1 = new Recipient();
    EmailAddress emailAddress1 = new EmailAddress();
    emailAddress1.setAddress("xxx@gmail.com");
    recipient1.setEmailAddress(emailAddress1);

    message1.setToRecipients(List.of(recipient1));

    SendMailPostRequestBody sendMailPostRequestBody1 = new SendMailPostRequestBody();
    sendMailPostRequestBody1.setMessage(message1);

    RequestInformation requestInformation1 =
            graphServiceClient.users()
                    .byUserId("xxx")
                    .sendMail()
                    .toPostRequestInformation(sendMailPostRequestBody1);

    batchRequestContent.addBatchRequestStep(requestInformation1);


    Message message2 = new Message();
    message2.setSubject("sub2");

    ItemBody body2 = new ItemBody();
    body2.setContentType(BodyType.Text);
    body2.setContent("body2wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww");
    message2.setBody(body2);

    Recipient recipient2 = new Recipient();
    EmailAddress emailAddress2 = new EmailAddress();
    emailAddress2.setAddress("xxx@gmail.com");
    recipient2.setEmailAddress(emailAddress2);

    message2.setToRecipients(List.of(recipient2));

    SendMailPostRequestBody sendMailPostRequestBody2 = new SendMailPostRequestBody();
    sendMailPostRequestBody2.setMessage(message2);

    RequestInformation requestInformation2 =
            graphServiceClient.users()
                    .byUserId("xxx")
                    .sendMail()
                    .toPostRequestInformation(sendMailPostRequestBody2);

    batchRequestContent.addBatchRequestStep(requestInformation2);
    graphServiceClient.getBatchRequestBuilder().post(batchRequestContent, null);
    System.out.println("hello");
}

How to reproduce

execute code with any correct credentials and email adderesses

public static void main(String[] args) throws IOException
{
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId("xxx")
.clientSecret("xxx")
.tenantId("xxx")
.build();
GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential,"https://graph.microsoft.com/.default");
BatchRequestContent batchRequestContent = new BatchRequestContent(graphServiceClient);

    Message message1 = new Message();
    message1.setSubject("sub1");

    ItemBody body1 = new ItemBody();
    body1.setContentType(BodyType.Text);
    body1.setContent( "body1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
    message1.setBody(body1);

    Recipient recipient1 = new Recipient();
    EmailAddress emailAddress1 = new EmailAddress();
    emailAddress1.setAddress("xxx@gmail.com");
    recipient1.setEmailAddress(emailAddress1);

    message1.setToRecipients(List.of(recipient1));

    SendMailPostRequestBody sendMailPostRequestBody1 = new SendMailPostRequestBody();
    sendMailPostRequestBody1.setMessage(message1);

    RequestInformation requestInformation1 =
            graphServiceClient.users()
                    .byUserId("xxx")
                    .sendMail()
                    .toPostRequestInformation(sendMailPostRequestBody1);

    batchRequestContent.addBatchRequestStep(requestInformation1);


    Message message2 = new Message();
    message2.setSubject("sub2");

    ItemBody body2 = new ItemBody();
    body2.setContentType(BodyType.Text);
    body2.setContent("body2wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww");
    message2.setBody(body2);

    Recipient recipient2 = new Recipient();
    EmailAddress emailAddress2 = new EmailAddress();
    emailAddress2.setAddress("xxx@gmail.com");
    recipient2.setEmailAddress(emailAddress2);

    message2.setToRecipients(List.of(recipient2));

    SendMailPostRequestBody sendMailPostRequestBody2 = new SendMailPostRequestBody();
    sendMailPostRequestBody2.setMessage(message2);

    RequestInformation requestInformation2 =
            graphServiceClient.users()
                    .byUserId("xxx")
                    .sendMail()
                    .toPostRequestInformation(sendMailPostRequestBody2);

    batchRequestContent.addBatchRequestStep(requestInformation2);
    graphServiceClient.getBatchRequestBuilder().post(batchRequestContent, null);
    System.out.println("hello");
}

SDK Version

6.13.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

                      <dependency>
				<groupId>com.microsoft.graph</groupId>
				<artifactId>microsoft-graph</artifactId>
				<version>6.13.0</version>
			</dependency>
			<dependency>
				<groupId>com.azure</groupId>
				<artifactId>azure-identity</artifactId>
				<version>1.12.2</version>
			</dependency> 

openjdk-21 (Oracle OpenJDK21 21.0.1)

### Other information

_No response_
@Rabbit2004Liza Rabbit2004Liza added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Oct 7, 2024
@Rabbit2004Liza Rabbit2004Liza changed the title BatchRequestContent don't work with big messages BatchRequestContent doesn't work with big messages Oct 7, 2024
@andrueastman
Copy link
Member

Thanks for raising this @Rabbit2004Liza

To confirm here, are you using the dotnet SDK? The syntax looks more like java and there is no version 6.13.0 for the C# sdk.

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Oct 7, 2024
@Rabbit2004Liza
Copy link
Author

Yes, I am using java SDK.
I have just noticed that I sent my issue in th wrong place.

Can you readdress it to https://github.com/microsoftgraph/msgraph-sdk-java/issues ?
Or I need to close it and create new one at https://github.com/microsoftgraph/msgraph-sdk-java/issues ?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants