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

Add quarkus.rest-client.multipart.max-chunk-size property #35982

Merged
merged 1 commit into from Sep 20, 2023

Conversation

ejba
Copy link
Contributor

@ejba ejba commented Sep 18, 2023

Closes #35915

@ejba
Copy link
Contributor Author

ejba commented Sep 18, 2023

WDYT @geoand?

@geoand
Copy link
Contributor

geoand commented Sep 18, 2023

Looks good on a first pass.

Have you tested it?

@ejba
Copy link
Contributor Author

ejba commented Sep 18, 2023

@geoand I added some unit tests. I'm trying to include some integration tests but I'm lacking creativity at the moment. Any suggestion?

@ejba ejba changed the title Add rest.client.max-chunk-size property Add rest-client.max-chunk-size property Sep 18, 2023
@ejba ejba changed the title Add rest-client.max-chunk-size property Add quarkus.rest-client.max-chunk-size property Sep 18, 2023
@geoand
Copy link
Contributor

geoand commented Sep 19, 2023

I would like to see something like:

public class ChunkedSizeTest {

    @RegisterExtension
    static final QuarkusUnitTest TEST = new QuarkusUnitTest()
            .withApplicationRoot((jar) -> jar.addClasses(TestClient.class, TestResource.class))
            .withConfigurationResource("chunked-size-test-application.properties");

    @Test
    public void test() throws Exception {
        // ensure that the response is what you expect
    }

    @Path("test")
    public interface TestClient {
        @POST
        @Produces(MediaType.TEXT_PLAIN)
        @Consumes(MediaType.TEXT_PLAIN)
        String test(byte[] input);
    }

    @Path("test")
    public static class TestResource {

        @POST
        @Produces(MediaType.TEXT_PLAIN)
        @Consumes(MediaType.TEXT_PLAIN)
        public String test(@Context HttpHeaders headers, byte[] input) {
            return input.length + "/" + headers.getLength() + "/" + headers.getHeaderString("transfer-encoding");
        }
    }
}

@geoand
Copy link
Contributor

geoand commented Sep 19, 2023

BTW, has this been tested against the server API mentioned in #35915?

@ejba
Copy link
Contributor Author

ejba commented Sep 19, 2023

BTW, has this been tested against the server API mentioned in #35915?

Not yet.

@ejba ejba force-pushed the 35915 branch 3 times, most recently from 0a6f8b5 to 1ee31ce Compare September 19, 2023 09:34
@ejba
Copy link
Contributor Author

ejba commented Sep 19, 2023

@geoand what is the expected behaviour when the multipart request content fits into a single chunk?

The http client chunks unconditionally the multipart requests.

Although there are servers which does not support payloads encoded into chunks, as trello API for example.

@geoand
Copy link
Contributor

geoand commented Sep 19, 2023

Hm... We took that from Netty and this issue seems to be exactly the same.

If I were you, I'd remove that check for multipart in a separate commit and run the tests to see what happens.

@ejba
Copy link
Contributor Author

ejba commented Sep 19, 2023

Wondering if the property name is explicit enough for developers to learn on their own that it is a specific configuration for multi-part requests. It might be wiser to add the intermediate level ("quarkus.rest-client.multipart.max-chunk-size") to make the configuration explict. WDTY?

@geoand
Copy link
Contributor

geoand commented Sep 19, 2023

It might be wiser to add the intermediate level ("quarkus.rest-client.multipart.max-chunk-size") to make the configuration explict. WDTY?

+1

@ejba ejba marked this pull request as ready for review September 19, 2023 14:26
@ejba ejba requested review from gsmet and geoand September 19, 2023 14:26
@ejba ejba changed the title Add quarkus.rest-client.max-chunk-size property Add quarkus.rest-client.multipart.max-chunk-size property Sep 19, 2023
@ejba ejba force-pushed the 35915 branch 2 times, most recently from a48ef94 to 1bd782f Compare September 19, 2023 15:15
@quarkus-bot

This comment has been minimized.

@quarkus-bot

This comment has been minimized.

@quarkus-bot

This comment has been minimized.

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 20, 2023

✔️ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

Comment on lines +862 to +869
if (fullRequest.content() != chunkContent && chunkContent != null) {
fullRequest.content().clear().writeBytes(chunkContent);
chunkContent.release();
} else if (chunkContent == null) {
isChunked = true;
removeChunkedFromTransferEncoding(headers);
}
return fullRequest;
return new WrappedHttpRequest(fullRequest);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain these changes please?

Copy link
Contributor Author

@ejba ejba Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without these changes, shouldSendFromMultiEmittingOutsideEventLoop and shouldUploadSlowlyProducedData test cases will fail (as you can see in the previous CI report).

The fetched HTTP chunk can be a null value and the request's content has to be marked as chunked because of that (based on my observation). Otherwise, an NPE will be thrown because the source buffer (i.e. the chunk) is a null value.

The reason for the buffer to be a null value on these test cases is unfortunately to be determined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think we can live with it as long as CI passes and as long as #35915 is fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could ask to the netty team what they think about these changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not burden them unless we really need to.

@geoand
Copy link
Contributor

geoand commented Sep 20, 2023

Thanks a lot for this @ejba!

Have you tried this against the use case mentioned in #35915?

@ejba
Copy link
Contributor Author

ejba commented Sep 20, 2023

Have you tried this against the use case mentioned in #35915?

No, I haven't yet. Honestly I think the added integration tests are similar to the use case mentioned in #35915 which gave my confidence to consider the PR as "ready". However, I agree it should be tested against to trello server.

@geoand
Copy link
Contributor

geoand commented Sep 20, 2023

The test looks good I agree, but we really need to test this against the real problematic server otherwise we can't close the issue 😉

@ejba
Copy link
Contributor Author

ejba commented Sep 20, 2023

Set the max-chunk-size property to 200_000.

image

image

@geoand
Copy link
Contributor

geoand commented Sep 20, 2023

That's awesome, thanks!

@geoand geoand merged commit 6fb2d3f into quarkusio:main Sep 20, 2023
31 checks passed
@quarkus-bot quarkus-bot bot added the kind/enhancement New feature or request label Sep 20, 2023
@quarkus-bot quarkus-bot bot added this to the 3.5 - main milestone Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[rest-client-reactive] Make the chunkSize customizable
3 participants