Skip to content

Proper way to dispose of Response [SPR-17268] #21801

Closed
@spring-projects-issues

Description

@spring-projects-issues

David Terk opened SPR-17268 and commented

Recently there was a fix that addressed some potential memory leaks if there were errors in the response to the Webclient.  Fix is here

#21563

If using exchange() what is the proper way to dispose of a response?  Can leaks still occur on bodyToMono(String.class) ? Trying to understand if this fix was specific to cases where bytebuffers are used e.g. 

return join(response.body(BodyExtractors.toDataBuffers()))
 .map(dataBuffer -> {
 byte[] bytes = new byte[dataBuffer.readableByteCount()];
 dataBuffer.read(bytes);
 DataBufferUtils.release(dataBuffer);
 return bytes;
 }).then();

or everywhere.

The above snippet is used directly in WebClients default error handler - so would like to know if this is the only "safe" way to deal with disposing a response if a non 200 status code has taken place after using exchange.

 


Affects: 5.0.8

Reference URL: #21563

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions