Skip to content

Fix buffer leak in ProtobufDecoder on cancel - #37543

Merged
bclozel merged 1 commit into
spring-projects:7.0.xfrom
sharanggupta:protobuf-decoder-cancel-leak
Oct 22, 2026
Merged

bclozel merged 1 commit into
spring-projects:7.0.xfrom
sharanggupta:protobuf-decoder-cancel-leak

Conversation

@sharanggupta

Copy link
Copy Markdown
Contributor

ProtobufDecoder.decode(Publisher) releases the buffer of a partially read message with doOnTerminate, so only when the input completes or fails. When the subscriber cancels while a message is split across data buffers, for example right after receiving the previous message, that buffer is never released. With pooled buffers, such as Netty's, it leaks.

This change uses doFinally instead, as AbstractCharSequenceDecoder does, so that the buffer is also released on cancel.

The new ProtobufDecoderTests#decodeCancelWhileMessageIncomplete decodes a data buffer that holds one message and half of the next, then cancels after the first message. Without the change, LeakAwareDataBufferFactory reports 1 buffer leak. The protobuf codec tests of spring-web and checkstyle pass.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 21, 2026
@bclozel
bclozel changed the base branch from main to 7.0.x October 22, 2026 08:12
@bclozel bclozel self-assigned this Oct 22, 2026
ProtobufDecoder released the buffer of a partially read message with
doOnTerminate, so only when the input completed or failed. When the
subscriber cancelled while a message was split across data buffers,
for example after receiving the previous message, that buffer was never
released.

Use doFinally instead, as AbstractCharSequenceDecoder does, so that the
buffer is also released on cancel.

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
@bclozel
bclozel force-pushed the protobuf-decoder-cancel-leak branch from 871c680 to 9397e6a Compare October 22, 2026 08:17
@bclozel bclozel added type: bug A general bug in: web Issues in web modules (web, webmvc, webflux, websocket) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 22, 2026
@bclozel bclozel added this to the 7.0.11 milestone Oct 22, 2026
@bclozel
bclozel merged commit 9397e6a into spring-projects:7.0.x Oct 22, 2026
1 check passed
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) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants