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

possible bug (deadlock) when posting batch request content over a certain length #1995

Open
dan-drewes opened this issue May 10, 2024 · 3 comments
Labels
priority:p0 Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs type:bug A broken experience

Comments

@dan-drewes
Copy link

dan-drewes commented May 10, 2024

There seems to be a bug with posting batch request content over a certain length (greater than DEFAULT_PIPE_SIZE = 1024 of PipedInputStream).

Calling graphClient.getBatchRequestBuilder().post(batchRequestContent, null)) goes into a deadlock.

Could you please check this?

Expected behavior

Graph API executes the batch request and returns some kind of response.

Actual behavior

Deadlock in

PipedInputStream.awaitSpace() line: 273
PipedInputStream.receive(byte[], int, int) line: 231
PipedOutputStream.write(byte[], int, int) line: 149
ByteArrayOutputStream.writeTo(OutputStream) line: 167
BatchRequestContent.getBatchRequestContent() line: 177
CustomBatchRequestBuilder(BatchRequestBuilder).toPostRequestInformation(BatchRequestContent) line: 84
CustomBatchRequestBuilder(BatchRequestBuilder).post(BatchRequestContent, Map<String,ParsableFactory>) line: 49
CustomBatchRequestBuilder.post(BatchRequestContent, Map<String,ParsableFactory>) line: 41
...

when calling

final BatchResponseContent batchResponseContent = Objects.requireNonNull(
            graphClient.getBatchRequestBuilder().post(batchRequestContent, null));

Steps to reproduce the behavior

Maven pom.xml

<dependency>
	      <groupId>com.microsoft.graph</groupId>
	      <artifactId>microsoft-graph</artifactId>
	      <version>6.8.0</version>
</dependency>
<dependency>
	      <groupId>com.azure</groupId>
	      <artifactId>azure-identity</artifactId>
	      <version>1.12.1</version>
</dependency>

Code:

// Create the batch request content with the steps
final BatchRequestContent batchRequestContent = new BatchRequestContent(
		graphClient);

//add some request steps to increase content length
for (int i = 1; i <= 9; i++)
{
	// Use the Graph client to generate the requestInformation object for GET /me
	final RequestInformation meRequestInformation = graphClient.me()
			.toGetRequestInformation();

	// Add the requestInformation objects to the batch request content
	batchRequestContent
			.addBatchRequestStep(meRequestInformation);
}

try
{
	// Send the batch request content to the /$batch endpoint
	final BatchResponseContent batchResponseContent = Objects.requireNonNull(
			graphClient.getBatchRequestBuilder().post(batchRequestContent, null));

	System.out.println("response received");

}
catch (IOException e)
{
	e.printStackTrace();
}
@kbullock-re
Copy link

Also experiencing this issue. Any advice would be appreciated.

@cschenkeltherolf
Copy link

cschenkeltherolf commented May 22, 2024

Also hitting this with BatchRequestContent.getBatchRequestContent(), same issue with the PipedInputStream. v3 was very much unaffected.

JavaDoc advises against using a PipedInputStream and PipedOutputStream on the same thread for this very reason.

https://docs.oracle.com/javase/8/docs/api/java/io/PipedInputStream.html

For my purposes, this was sufficient, as I'm writing the content of the BatchRequestContent to my own request container and emitting it through our own IO.

return outputStream.toString(StandardCharsets.UTF_8);

@petrhollayms
Copy link

@Ndiritu BatchRequestContent shall not be using PipedInputStream, could you please check?

@petrhollayms petrhollayms added type:bug A broken experience priority:p0 Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:p0 Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

4 participants