Skip to content

Fix duplicate completion handling in DataBufferUtils - #37391

Open
abrar2309 wants to merge 1 commit into
spring-projects:mainfrom
abrar2309:learning/spring-mvc-navigation
Open

abrar2309 wants to merge 1 commit into
spring-projects:mainfrom
abrar2309:learning/spring-mvc-navigation

Conversation

@abrar2309

Copy link
Copy Markdown

Fix duplicate completion handling in DataBufferUtils.readAsynchronousFileChannel().

Problem

On Windows, an AsynchronousFileChannel completion handler may be invoked more than once for the same read operation.

ReadCompletionHandler.completed() currently processes each callback independently. If the same Attachment is delivered to completed() twice, the associated DataBuffer can be released more than once.

Solution

Associate an AtomicBoolean completion guard with each Attachment.

The first invocation of completed() marks the attachment as completed and proceeds normally. Any subsequent invocation for the same attachment returns immediately.

This prevents duplicate completion callbacks from closing the iterator and releasing the same DataBuffer more than once.

Tests

Added a regression test that invokes the completion handler twice with the same attachment and verifies that the PooledDataBuffer is released only once.

Validation

  • :spring-core:test --tests "org.springframework.core.io.buffer.DataBufferUtilsTests.readAsynchronousFileChannelDuplicateCompletion"
  • :spring-core:compileJava

Both completed successfully.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 4, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Oct 4, 2026

This branch has not been deployed

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

Labels

in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants