spring-projects / spring-projects/spring-ws

Reference to response payload is kept in each thread [SWS-1070]

Open
#1,136 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

for: team-attention status: waiting-for-triage
Dominant language
Java
Stars
346
Forks
323
Avg merge
3d 2h
Merged PRs (30d)
7

Description

smaxi opened SWS-1070 and commented

Each thread of the application keeps reference to response payload. This reference is getting cleaned/reused when thread gets used again.
This behavior is abnormal, because keeping reference to payload causes OoM when number of threads is high and payloads are big. It is not question of sizing of jvm as permanent heap requirements are n*m where n is the max size of the pool and m is the biggest size of response of the application.

How to reproduce:

Consider a method that returns StreamSource.
@PayloadRoot(namespace = PULLACK_NAMESPACE_URI, localPart = "PullRequest") @ResponsePayload public StreamSource requestDataGetEvents(@RequestPayload XMLStreamReader reader) throws DurableStorageException{……
and ensure that reply is big enough, then memory footprint would look similar to:
!https://user-images.githubusercontent.com/50314851/57211152-88802380-6fdf-11e9-87d3-32419659a846.png!

The reference to memory is kept and thread goes back to pool after processing the reply to the client. This reference is replaced by new reference once thread gets reused.

Ideas about resolution: either output stream is not closed, either reference to payload is not cleaned correctly.

Workaround: manipulate streams directly in the application which is not the objective here.

Cleanup thread locals by putting interceptor when output is sent to client<= a dirty way to achieve the needed behavior.

This is a copy-paste of the closed issue reported in: https://github.com/spring-projects/spring-framework/issues/22895

 


Affects: 2.3.1, 2.4.5, 3.0.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with a method returning StreamSource and a sufficiently large response, then observe memory while pooled threads process repeated replies. Investigate how the response output stream and payload reference are handled when a thread returns to the pool. Done means payload references are released or cleaned before reuse and memory no longer grows with pool size.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.