Skip to content

Fix Bug : RemoveCachedBodyFilter does not release direct memory correctly resulting in a memory leak #2969#2971

Closed
caixunshi wants to merge 1 commit intospring-cloud:3.1.xfrom
caixunshi:fix/outOfDirectMemoryError
Closed

Fix Bug : RemoveCachedBodyFilter does not release direct memory correctly resulting in a memory leak #2969#2971
caixunshi wants to merge 1 commit intospring-cloud:3.1.xfrom
caixunshi:fix/outOfDirectMemoryError

Conversation

@caixunshi
Copy link
Copy Markdown
Contributor

Fixes #2969

RemoveCachedBodyFilter uses the remove method to remove CACHED_REQUEST_BODY_ATTR from the exchange object, but it cannot guarantee that the dataBuffer will be released correctly.

When calling ServerWebExchangeUtils.cacheRequestBody multiple times in the project to generate a nested multi-layer ServerHttpRequestDecorator, it will cause a memory leak and eventually throw an OutOfDirectMemoryError

So in RemoveCachedBodyFilter, it should be ensured that the cached dataBuffer is released correctly.

This PR contains a fix for this problem. The idea is to ensure that databuf is released correctly by judging the return value of release.

Please review this PR, if looks ok please approve it.

@caixunshi
Copy link
Copy Markdown
Contributor Author

@spencergibb

@chocotan
Copy link
Copy Markdown

After several days of troubleshooting, we finally discovered that this pull request is the correct solution.

#2842 with this commit can not fix memory leak problem completely.

@caixunshi
Copy link
Copy Markdown
Contributor Author

@spencergibb why hasn't this PR request been addressed yet? Is there any issue with it?

@spencergibb
Copy link
Copy Markdown
Member

Closed via aa88517 and polished in ea3662d

@dtsukinovsky

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

RemoveCachedBodyFilter does not release direct memory correctly resulting in a memory leak

5 participants