Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate CompletedFileUpload in publisher if route is delayed #10713

Merged
merged 4 commits into from
Apr 16, 2024

Conversation

yawkat
Copy link
Member

@yawkat yawkat commented Apr 15, 2024

Draft because this depends on #10712 to avoid a merge conflict in the test. Will retarget to 4.4.x when #10712 is merged


NettyPublisherPartUploadBinder is designed to emit a HttpData every time a piece of the input data is received. The data is then converted to the specified publisher type. For CompletedFileUpload, NettyConvertersSpi checks whether the HttpData is completed, so the output should only include the final HttpData for the particular part.

However, when the route has another argument that delays its execution until all parts have been fully received, this assumption fails. The publisher will buffer all the HttpData, and when the conversion happens, all of these HttpData are isComplete (since at that point the full part has been received). This leads to the same CompletedFileUpload being emitted many times.

This patch changes NettyPublisherPartUploadBinder to use claimFieldsComplete instead of claimFieldsRaw to ensure that the same part does not appear multiple times in the first place.

Fixes #10578

Reactor does not like null elements, so if the refCountAwareConvert fails, there would be an NPE.

Fixes #10578
NettyPublisherPartUploadBinder is designed to emit a HttpData every time a piece of the input data is received. The data is then converted to the specified publisher type. For CompletedFileUpload, NettyConvertersSpi checks whether the HttpData is completed, so the output should only include the final HttpData for the particular part.

However, when the route has another argument that delays its execution until all parts have been fully received, this assumption fails. The publisher will buffer all the HttpData, and when the conversion happens, all of these HttpData are isComplete (since at that point the full part has been received). This leads to the same CompletedFileUpload being emitted many times.

This patch changes NettyPublisherPartUploadBinder to use claimFieldsComplete instead of claimFieldsRaw to ensure that the same part does not appear multiple times in the first place.

Fixes #10578
@yawkat yawkat added the type: bug Something isn't working label Apr 15, 2024
@yawkat yawkat added this to the 4.4.2 milestone Apr 15, 2024
Base automatically changed from bind-npe to 4.4.x April 15, 2024 09:23
@yawkat yawkat marked this pull request as ready for review April 15, 2024 09:23
# Conflicts:
#	http-server-netty/src/test/groovy/io/micronaut/http/server/netty/FileUploadSpec.groovy
Copy link

sonarcloud bot commented Apr 15, 2024

@sdelamo sdelamo merged commit f2797d9 into 4.4.x Apr 16, 2024
17 checks passed
@sdelamo sdelamo deleted the bind-delay branch April 16, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants