You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/05/12 08:56:25 UTC

[camel] branch camel-3.14.x updated: CAMEL-18101: camel-core - Pooled exchanges with netty-http/jetty/servlet can cause reference leaks

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.14.x by this push:
     new 4bd589f085b CAMEL-18101: camel-core - Pooled exchanges with netty-http/jetty/servlet can cause reference leaks
4bd589f085b is described below

commit 4bd589f085b512e745693c9184610cc51bf3c344
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu May 12 10:34:21 2022 +0200

    CAMEL-18101: camel-core - Pooled exchanges with netty-http/jetty/servlet can cause reference leaks
---
 .../netty/http/handlers/HttpServerChannelHandler.java     |  4 ++++
 .../netty/http/NettyHttpSimplePooledExchangeTest.java     | 15 +++++++++------
 .../java/org/apache/camel/support/DefaultConsumer.java    | 10 +++++++---
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
index dea2054998d..b2ba87ce23d 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
@@ -344,6 +344,10 @@ public class HttpServerChannelHandler extends ServerChannelHandler {
     protected Exchange createExchange(ChannelHandlerContext ctx, Object message) throws Exception {
         Exchange exchange = this.consumer.createExchange(false);
 
+        if (exchange.getUnitOfWork() != null) {
+            System.out.println(">>> UoW is NOT NULL <<< " + exchange);
+        }
+
         // create a new IN message as we cannot reuse with netty
         Message in;
         if (message instanceof FullHttpRequest) {
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSimplePooledExchangeTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSimplePooledExchangeTest.java
index d2e96346bc8..75b9b54822b 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSimplePooledExchangeTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSimplePooledExchangeTest.java
@@ -37,22 +37,25 @@ public class NettyHttpSimplePooledExchangeTest extends BaseNettyTest {
     public void testOne() throws Exception {
         getMockEndpoint("mock:input").expectedBodiesReceived("World");
 
-        String out = template.requestBody("netty-http:http://localhost:{{port}}/foo", "World", String.class);
+        String out = template.requestBody("netty-http:http://localhost:{{port}}/pooled", "World", String.class);
         assertEquals("Bye World", out);
 
         assertMockEndpointsSatisfied();
     }
 
     @Test
-    public void testTwo() throws Exception {
-        getMockEndpoint("mock:input").expectedBodiesReceived("World", "Camel");
+    public void testThree() throws Exception {
+        getMockEndpoint("mock:input").expectedBodiesReceived("World", "Camel", "Earth");
 
-        String out = template.requestBody("netty-http:http://localhost:{{port}}/foo", "World", String.class);
+        String out = template.requestBody("netty-http:http://localhost:{{port}}/pooled", "World", String.class);
         assertEquals("Bye World", out);
 
-        out = template.requestBody("netty-http:http://localhost:{{port}}/foo", "Camel", String.class);
+        out = template.requestBody("netty-http:http://localhost:{{port}}/pooled", "Camel", String.class);
         assertEquals("Bye Camel", out);
 
+        out = template.requestBody("netty-http:http://localhost:{{port}}/pooled", "Earth", String.class);
+        assertEquals("Bye Earth", out);
+
         assertMockEndpointsSatisfied();
     }
 
@@ -61,7 +64,7 @@ public class NettyHttpSimplePooledExchangeTest extends BaseNettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("netty-http:http://0.0.0.0:{{port}}/foo")
+                from("netty-http:http://0.0.0.0:{{port}}/pooled")
                         .convertBodyTo(String.class)
                         .to("mock:input")
                         .transform().simple("Bye ${body}");
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
index bbb0cc4519b..8bbf6e3aefc 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
@@ -110,9 +110,13 @@ public class DefaultConsumer extends ServiceSupport implements Consumer, RouteAw
             exchange.adapt(ExtendedExchange.class).setFromRouteId(route.getId());
         }
 
-        UnitOfWork uow = endpoint.getCamelContext().adapt(ExtendedCamelContext.class).getUnitOfWorkFactory()
-                .createUnitOfWork(exchange);
-        exchange.adapt(ExtendedExchange.class).setUnitOfWork(uow);
+        // create uow (however for pooled exchanges then the uow is pre-created)
+        UnitOfWork uow = exchange.getUnitOfWork();
+        if (uow == null) {
+            uow = endpoint.getCamelContext().adapt(ExtendedCamelContext.class).getUnitOfWorkFactory()
+                    .createUnitOfWork(exchange);
+            exchange.adapt(ExtendedExchange.class).setUnitOfWork(uow);
+        }
         return uow;
     }