Skip to content

SseEmitter (ResponseBodyEmitter) keeps collecting messages if not initialized #25442

@kgcsabi

Description

@kgcsabi

Details

Component: spring-webmvc
Affects: 5.2.7.RELEASE
Impact: Memory leak

Description

The ResponseBodyEmitter instance is normally initialized by the framework upon returned by the RestController method.
The messages that are passed in the meantime are collected in a LinkedHashSet.

When the connection is dropped by the client early enough then the initialization will never be invoked.

These instances keep collecting the messages with no limitation.
To make matters worse, these instances are not evicted when timeout is reached.

This may result in OutOfMemoryError on the long run.

Steps to reproduce:

  1. Start Server app in debug mode
  2. Add breakpoint to org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitterReturnValueHandler:129 //emitter.initialize(handler);
  3. Start Client app
  4. When breakpoint hit then stop Client app

Attachments

Ideas

In my opinion this may be addressed by

  • limiting the time waiting for initialization
  • limiting the number of messages kept before initialization
  • a combination of the above
  • a custom handler for early send attempts

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions