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

Upgrade to Vert.x 4.4.9 with backports #39788

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<wildfly-client-config.version>1.0.1.Final</wildfly-client-config.version>
<wildfly-elytron.version>2.2.1.Final</wildfly-elytron.version>
<jboss-threads.version>3.5.0.Final</jboss-threads.version>
<vertx.version>4.4.8</vertx.version>
<vertx.version>4.4.9</vertx.version>
<httpclient.version>4.5.14</httpclient.version>
<httpcore.version>4.4.16</httpcore.version>
<httpasync.version>4.1.5</httpasync.version>
Expand All @@ -145,7 +145,7 @@
<infinispan.version>14.0.11.Final</infinispan.version>
<infinispan.protostream.version>4.6.2.Final</infinispan.protostream.version>
<caffeine.version>3.1.5</caffeine.version>
<netty.version>4.1.100.Final</netty.version>
<netty.version>4.1.108.Final</netty.version>
<brotli4j.version>1.12.0</brotli4j.version>
<reactive-streams.version>1.0.4</reactive-streams.version>
<jboss-logging.version>3.5.1.Final</jboss-logging.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ NativeImageConfigBuildItem nativeImageConfiguration() {
.addRuntimeInitializedClass("io.grpc.netty.Utils")
.addRuntimeInitializedClass("io.grpc.netty.NettyServerBuilder")
.addRuntimeInitializedClass("io.grpc.netty.NettyChannelBuilder")
.addRuntimeInitializedClass("io.grpc.internal.RetriableStream");
.addRuntimeInitializedClass("io.grpc.internal.RetriableStream")
.addRuntimeReinitializedClass("com.google.protobuf.UnsafeUtil");
return builder.build();
}

Expand Down
19 changes: 19 additions & 0 deletions extensions/grpc-common/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,28 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.android</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.grpc.InternalServiceProviders.getCandidatesViaHardCoded;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -12,6 +13,8 @@
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

import sun.misc.Unsafe;

@SuppressWarnings("unused")
@TargetClass(className = "io.grpc.ServiceProviders")
final class Target_io_grpc_ServiceProviders { // NOSONAR
Expand Down Expand Up @@ -79,6 +82,20 @@ interface Target_io_grpc_ServiceProviders_PriorityAccessor<T> { // NOSONAR
int getPriority(T provider);
}

@TargetClass(className = "com.google.protobuf.UnsafeUtil")
final class Target_com_google_protobuf_UnsafeUtil {
@Substitute
static sun.misc.Unsafe getUnsafe() {
try {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
return (Unsafe) theUnsafe.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

@SuppressWarnings("unused")
class GrpcSubstitutions {
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ InfinispanPropertiesBuildItem setup(ApplicationArchivesBuildItem applicationArch
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(InfinispanClientName.class).build());
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(Remote.class).build());

systemProperties.produce(new SystemPropertyBuildItem("io.netty.noUnsafe", "true"));
hotDeployment
.produce(new HotDeploymentWatchedFileBuildItem(META_INF + File.separator + DEFAULT_HOTROD_CLIENT_PROPERTIES));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ NativeImageConfigBuildItem build(
.addRuntimeInitializedClass("io.netty.handler.ssl.ReferenceCountedOpenSslEngine")
.addRuntimeInitializedClass("io.netty.handler.ssl.ReferenceCountedOpenSslContext")
.addRuntimeInitializedClass("io.netty.handler.ssl.ReferenceCountedOpenSslClientContext")
.addRuntimeInitializedClass("io.netty.handler.ssl.JdkSslServerContext")
.addRuntimeInitializedClass("io.netty.handler.ssl.JdkSslClientContext")
.addRuntimeInitializedClass("io.netty.handler.ssl.util.ThreadLocalInsecureRandom")
.addRuntimeInitializedClass("io.netty.buffer.ByteBufUtil$HexUtil")
.addRuntimeInitializedClass("io.netty.buffer.PooledByteBufAllocator")
Expand All @@ -120,6 +122,7 @@ NativeImageConfigBuildItem build(
.addRuntimeInitializedClass("io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder")
.addRuntimeInitializedClass("io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder")
.addRuntimeInitializedClass("io.netty.handler.codec.compression.ZstdOptions")
.addRuntimeInitializedClass("io.netty.handler.codec.compression.ZstdConstants")
.addRuntimeInitializedClass("io.netty.handler.codec.compression.BrotliOptions");
} else {
log.debug("Not registering Netty HTTP classes as they were not found");
Expand Down Expand Up @@ -162,6 +165,28 @@ NativeImageConfigBuildItem build(
log.debug("Not registering Netty native kqueue classes as they were not found");
}

builder.addRuntimeReinitializedClass("io.netty.util.internal.PlatformDependent")
.addRuntimeReinitializedClass("io.netty.util.internal.PlatformDependent0");

if (QuarkusClassLoader.isClassPresentAtRuntime("io.netty.buffer.UnpooledByteBufAllocator")) {
builder.addRuntimeReinitializedClass("io.netty.buffer.UnpooledByteBufAllocator")
.addRuntimeReinitializedClass("io.netty.buffer.Unpooled")
.addRuntimeReinitializedClass("io.vertx.core.http.impl.Http1xServerResponse")
.addRuntimeReinitializedClass("io.netty.handler.codec.http.HttpObjectAggregator")
.addRuntimeReinitializedClass("io.netty.handler.codec.ReplayingDecoderByteBuf")
.addRuntimeReinitializedClass("io.vertx.core.parsetools.impl.RecordParserImpl");

if (QuarkusClassLoader.isClassPresentAtRuntime("io.vertx.ext.web.client.impl.MultipartFormUpload")) {
builder.addRuntimeReinitializedClass("io.vertx.ext.web.client.impl.MultipartFormUpload");
}

if (QuarkusClassLoader
.isClassPresentAtRuntime("org.jboss.resteasy.reactive.client.impl.multipart.QuarkusMultipartFormUpload")) {
builder.addRuntimeReinitializedClass(
"org.jboss.resteasy.reactive.client.impl.multipart.QuarkusMultipartFormUpload");
}
}

return builder //TODO: make configurable
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ public void flush(final ChannelHandlerContext ctx) {
}
}

@Substitute
@TargetClass(className = "io.netty.handler.codec.compression.ZstdConstants", onlyWith = IsZstdAbsent.class)
public static final class ZstdConstants {

// The constants make <clinit> calls to com.github.luben.zstd.Zstd so we cut links with that substitution.

static final int DEFAULT_COMPRESSION_LEVEL = 0;

static final int MIN_COMPRESSION_LEVEL = 0;

static final int MAX_COMPRESSION_LEVEL = 0;

static final int MAX_BLOCK_SIZE = 0;

static final int DEFAULT_BLOCK_SIZE = 0;
}

public static class IsZstdAbsent implements BooleanSupplier {

private boolean zstdAbsent;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package io.quarkus.vertx.http.form;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.RequestOptions;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.BodyHandler;

public class FormTest {

private static final String APP_PROPS = "quarkus.http.limits.max-form-fields=10\n" +
"quarkus.http.limits.max-form-buffered-bytes=100\n";

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addAsResource(new StringAsset(APP_PROPS), "application.properties")
.addClasses(BeanRegisteringRouteUsingObserves.class));

@Inject
Vertx vertx;

@Test
public void testTooManyFields() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<HttpClientResponse> reference = new AtomicReference<>();
HttpClient client = vertx.createHttpClient();
client.request(new RequestOptions().setMethod(HttpMethod.POST).setAbsoluteURI("http://localhost:8081/form"))
.onComplete(ar -> {
var req = ar.result();
req.setChunked(true);
req.putHeader("content-type", "application/x-www-form-urlencoded");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 20; i++) {
if (i > 0) {
sb.append('&');
}
sb.append("a").append(i).append("=").append("b");
}
req.write(sb.toString());
vertx.setTimer(10, id -> {
req.end();
});

req.response().onComplete(rc -> {
reference.set(rc.result());
latch.countDown();
});
});
latch.await(10, TimeUnit.SECONDS);
Assertions.assertEquals(400, reference.get().statusCode());
}

@Test
public void testOkForm() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<HttpClientResponse> reference = new AtomicReference<>();
HttpClient client = vertx.createHttpClient();
client.request(new RequestOptions().setMethod(HttpMethod.POST).setAbsoluteURI("http://localhost:8081/form"))
.onComplete(ar -> {
var req = ar.result();
req.setChunked(true);
req.putHeader("content-type", "application/x-www-form-urlencoded");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; i++) {
if (i > 0) {
sb.append('&');
}
sb.append("a").append(i).append("=").append("b");
}
req.write(sb.toString());
vertx.setTimer(10, id -> {
req.end();
});

req.response().onComplete(rc -> {
reference.set(rc.result());
latch.countDown();
});
});
latch.await(10, TimeUnit.SECONDS);
Assertions.assertEquals(200, reference.get().statusCode());
}

@Test
public void testTooManyBytes() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<HttpClientResponse> reference = new AtomicReference<>();
HttpClient client = vertx.createHttpClient();
client.request(new RequestOptions().setMethod(HttpMethod.POST).setAbsoluteURI("http://localhost:8081/form"))
.onComplete(ar -> {
var req = ar.result();
req.setChunked(true);
req.putHeader("content-type", "application/x-www-form-urlencoded");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 200; i++) {
sb.append("a");
}
req.write(sb.toString());
vertx.setTimer(10, id -> {
req.end("=b");
});

req.response().onComplete(rc -> {
reference.set(rc.result());
latch.countDown();
});
});
latch.await(10, TimeUnit.SECONDS);
Assertions.assertEquals(400, reference.get().statusCode());
}

@Test
public void testBytesOk() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<HttpClientResponse> reference = new AtomicReference<>();
HttpClient client = vertx.createHttpClient();
client.request(new RequestOptions().setMethod(HttpMethod.POST).setAbsoluteURI("http://localhost:8081/form"))
.onComplete(ar -> {
var req = ar.result();
req.setChunked(true);
req.putHeader("content-type", "application/x-www-form-urlencoded");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++) {
sb.append("a");
}
req.write(sb.toString());
vertx.setTimer(10, id -> {
req.end("=b");
});

req.response().onComplete(rc -> {
reference.set(rc.result());
latch.countDown();
});
});
latch.await(10, TimeUnit.SECONDS);
Assertions.assertEquals(200, reference.get().statusCode());
}

@ApplicationScoped
static class BeanRegisteringRouteUsingObserves {

public void register(@Observes Router router) {

router
.post().order(Integer.MIN_VALUE).handler(rc -> {
rc.request().setExpectMultipart(true);
rc.next();
});
router.post().handler(BodyHandler.create());
router.post("/form")
.handler(rc -> {
rc.response().end("OK");
});
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ public class ServerLimitsConfig {
@ConfigItem(defaultValue = "2048")
public MemorySize maxFormAttributeSize;

/**
* Set the maximum number of fields of a form. Set to {@code -1} to allow unlimited number of attributes.
*/
@ConfigItem(defaultValue = "256")
public int maxFormFields;

/**
* Set the maximum number of bytes a server can buffer when decoding a form.
* Set to {@code -1} to allow unlimited length
**/
@ConfigItem(defaultValue = "1K")
public MemorySize maxFormBufferedBytes;

/**
* The maximum number of HTTP request parameters permitted for incoming requests.
* <p>
* If a client sends more than this number of parameters in a request, the connection is closed.
*/
@ConfigItem(defaultValue = "1000")
public int maxParameters;
Copy link
Member

Choose a reason for hiding this comment

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

@jponge this config parameter doesn't seem to be used

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, it might be removed


/**
* The maximum number of connections that are allowed at any one time. If this is set
* it is recommended to set a short idle timeout.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public static void applyCommonOptions(HttpServerOptions httpServerOptions,
httpServerOptions.setMaxHeaderSize(httpConfiguration.limits.maxHeaderSize.asBigInteger().intValueExact());
httpServerOptions.setMaxChunkSize(httpConfiguration.limits.maxChunkSize.asBigInteger().intValueExact());
httpServerOptions.setMaxFormAttributeSize(httpConfiguration.limits.maxFormAttributeSize.asBigInteger().intValueExact());
httpServerOptions.setMaxFormFields(httpConfiguration.limits.maxFormFields);
httpServerOptions.setMaxFormBufferedBytes(httpConfiguration.limits.maxFormBufferedBytes.asBigInteger().intValue());
httpServerOptions.setWebSocketSubProtocols(websocketSubProtocols);
httpServerOptions.setReusePort(httpConfiguration.soReusePort);
httpServerOptions.setTcpQuickAck(httpConfiguration.tcpQuickAck);
Expand Down Expand Up @@ -317,6 +319,8 @@ public static void applyCommonOptionsForManagementInterface(HttpServerOptions op
options.setMaxHeaderSize(httpConfiguration.limits.maxHeaderSize.asBigInteger().intValueExact());
options.setMaxChunkSize(httpConfiguration.limits.maxChunkSize.asBigInteger().intValueExact());
options.setMaxFormAttributeSize(httpConfiguration.limits.maxFormAttributeSize.asBigInteger().intValueExact());
options.setMaxFormFields(httpConfiguration.limits.maxFormFields);
options.setMaxFormBufferedBytes(httpConfiguration.limits.maxFormBufferedBytes.asBigInteger().intValue());
options.setMaxInitialLineLength(httpConfiguration.limits.maxInitialLineLength);
options.setWebSocketSubProtocols(websocketSubProtocols);
options.setAcceptBacklog(httpConfiguration.acceptBacklog);
Expand Down
Loading
Loading