Skip to content

The OkHttp3ClientHttpRequestFactory caches the request body. When the request body is too large, an OOM occurs. #28535

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

Closed
DInTheName opened this issue May 28, 2022 · 2 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@DInTheName
Copy link

The OkHttp3ClientHttpRequestFactory caches the request body. When the request body is too large, an OOM occurs.
The RestTemplate is:

  OkHttp3ClientHttpRequestFactory factory =
                new OkHttp3ClientHttpRequestFactory(new OkHttpClient());
            RestTemplate   restTemplate = new RestTemplate(factory);

But when i user OkHttp3Clientto upload this file, it is successful.

My question is why the SimpleClientHttpRequestFactory can set bufferRequestBody?

	@Override
	public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
		HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
		prepareConnection(connection, httpMethod.name());

		if (this.bufferRequestBody) {
			return new SimpleBufferingClientHttpRequest(connection, this.outputStreaming);
		}
		else {
			return new SimpleStreamingClientHttpRequest(connection, this.chunkSize, this.outputStreaming);
		}
	}

but OkHttp3ClientHttpRequestFactory without this switch?

I want to use the OkHttp3ClientHttpRequestFactory object without caching the request body,How can I do it?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 28, 2022
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jan 24, 2023
@hision
Copy link

hision commented Jun 13, 2023

@DInTheName I have also encountered this problem. Have you found a solution?

@snicoll
Copy link
Member

snicoll commented Oct 8, 2023

In the meantime, OkHttp3ClientHttpRequestFactory has been deprecated so I am afraid this issue should be closed for consistency.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Oct 8, 2023
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

5 participants