Skip to content

Re-serialization of serialized object that was sent with request can lead to OutOfMemoryError #750

@mike-harris0n

Description

@mike-harris0n

Starting at com.microsoft.graph.http.CoreHttpProvider#processResponse, if a request fails it attempts to serialize (again) the input object that was sent in the request at com.microsoft.graph.http.GraphServiceException#createFromResponse(com.microsoft.graph.http.IHttpRequest, T, com.microsoft.graph.serializer.ISerializer, okhttp3.Response, com.microsoft.graph.logger.ILogger). Why does it need to serialize again? It would be great if it was possible to avoid this and just return a usable exception object.

Our app sends customer-created emails via multiple services including MS365 via Graph. Sometimes the sent emails can be large. We are already having to use a CustomRequest as a crutch in order to properly send pre-built MIME email strings. I'm beginning to think we might be better off using the Java Graph API to create the URLs and use our own HTTP client so that we don't have to deal with this...

Expected behavior

Error responses can be handled without excessive additional memory consumption.

Actual behavior

pool-768-thread-1
  at java.lang.OutOfMemoryError.<init>()V (Unknown Source)
  at java.util.Arrays.copyOf([BI)[B (Unknown Source)
  at java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V (Unknown Source)
  at java.lang.AbstractStringBuilder.append(Ljava/lang/CharSequence;II)Ljava/lang/AbstractStringBuilder; (Unknown Source)
  at java.lang.StringBuffer.append(Ljava/lang/CharSequence;II)Ljava/lang/StringBuffer; (Unknown Source)
  at java.io.StringWriter.write(Ljava/lang/String;II)V (Unknown Source)
  at com.google.gson.stream.JsonWriter.string(Ljava/lang/String;)V (JsonWriter.java:637)
  at com.google.gson.stream.JsonWriter.value(Ljava/lang/String;)Lcom/google/gson/stream/JsonWriter; (JsonWriter.java:426)
  at com.google.gson.internal.bind.TypeAdapters$28.write(Lcom/google/gson/stream/JsonWriter;Lcom/google/gson/JsonElement;)V (TypeAdapters.java:805)
  at com.google.gson.internal.bind.TypeAdapters$28.write(Lcom/google/gson/stream/JsonWriter;Ljava/lang/Object;)V (TypeAdapters.java:698)
  at com.google.gson.internal.Streams.write(Lcom/google/gson/JsonElement;Lcom/google/gson/stream/JsonWriter;)V (Streams.java:72)
  at com.google.gson.JsonElement.toString()Ljava/lang/String; (JsonElement.java:316)
  at com.microsoft.graph.serializer.DefaultSerializer.serializeObject(Ljava/lang/Object;)Ljava/lang/String; (DefaultSerializer.java:233)
  at com.microsoft.graph.http.GraphServiceException.createFromResponse(Lcom/microsoft/graph/http/IHttpRequest;Ljava/lang/Object;Lcom/microsoft/graph/serializer/ISerializer;Lokhttp3/Response;Lcom/microsoft/graph/logger/ILogger;)Lcom/microsoft/graph/http/GraphServiceException; (GraphServiceException.java:368)
  at com.microsoft.graph.http.CoreHttpProvider.handleErrorResponse(Lcom/microsoft/graph/http/IHttpRequest;Ljava/lang/Object;Lokhttp3/Response;)V (CoreHttpProvider.java:512)
  at com.microsoft.graph.http.CoreHttpProvider.processResponse(Lokhttp3/Response;Lcom/microsoft/graph/http/IHttpRequest;Ljava/lang/Class;Ljava/lang/Object;Lcom/microsoft/graph/http/IStatefulResponseHandler;)Ljava/lang/Object; (CoreHttpProvider.java:442)
  at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(Lcom/microsoft/graph/http/IHttpRequest;Ljava/lang/Class;Ljava/lang/Object;Lcom/microsoft/graph/http/IStatefulResponseHandler;)Ljava/lang/Object; (CoreHttpProvider.java:408)
  at com.microsoft.graph.http.CoreHttpProvider.send(Lcom/microsoft/graph/http/IHttpRequest;Ljava/lang/Class;Ljava/lang/Object;Lcom/microsoft/graph/http/IStatefulResponseHandler;)Ljava/lang/Object; (CoreHttpProvider.java:225)
  at com.microsoft.graph.http.CoreHttpProvider.send(Lcom/microsoft/graph/http/IHttpRequest;Ljava/lang/Class;Ljava/lang/Object;)Ljava/lang/Object; (CoreHttpProvider.java:202)
  at com.microsoft.graph.http.BaseRequest.send(Lcom/microsoft/graph/http/HttpMethod;Ljava/lang/Object;)Ljava/lang/Object; (BaseRequest.java:335)
  at com.microsoft.graph.http.CustomRequest.post(Ljava/lang/Object;)Ljava/lang/Object; (CustomRequest.java:154)

Steps to reproduce the behavior

  1. Send custom POST request with large MIME email string, that results in 400 error response

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions