From 0b0a2061f7ee9c33ae513c02cfde31cf9bfe7e8f Mon Sep 17 00:00:00 2001 From: guerrillakg Date: Mon, 4 May 2026 15:36:52 +0200 Subject: [PATCH 1/3] 6044 Do not complete requests on receiving notification events --- .../AsyncContextDelegateProviderImpl.java | 4 +- tests/integration/jersey-6044/pom.xml | 40 ++++++ .../tests/jettyresponseclose/Resource204.java | 39 ++++++ .../JettyHttpContainerDuringShutdownTest.java | 118 ++++++++++++++++++ .../src/test/resources/surefire.policy | 45 +++++++ tests/integration/pom.xml | 2 + 6 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 tests/integration/jersey-6044/pom.xml create mode 100644 tests/integration/jersey-6044/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource204.java create mode 100644 tests/integration/jersey-6044/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerDuringShutdownTest.java create mode 100644 tests/integration/jersey-6044/src/test/resources/surefire.policy diff --git a/containers/jersey-servlet/src/main/java/org/glassfish/jersey/servlet/async/AsyncContextDelegateProviderImpl.java b/containers/jersey-servlet/src/main/java/org/glassfish/jersey/servlet/async/AsyncContextDelegateProviderImpl.java index 89fa99a7c86..5758199047e 100644 --- a/containers/jersey-servlet/src/main/java/org/glassfish/jersey/servlet/async/AsyncContextDelegateProviderImpl.java +++ b/containers/jersey-servlet/src/main/java/org/glassfish/jersey/servlet/async/AsyncContextDelegateProviderImpl.java @@ -83,7 +83,7 @@ private class CompletedAsyncContextListener implements AsyncListener { @Override public void onComplete(AsyncEvent event) throws IOException { - complete(); + completed.set(true); } @Override @@ -93,7 +93,7 @@ public void onTimeout(AsyncEvent event) throws IOException { @Override public void onError(AsyncEvent event) throws IOException { - complete(); + completed.set(true); } @Override diff --git a/tests/integration/jersey-6044/pom.xml b/tests/integration/jersey-6044/pom.xml new file mode 100644 index 00000000000..9454fa7c27d --- /dev/null +++ b/tests/integration/jersey-6044/pom.xml @@ -0,0 +1,40 @@ + + + + project + org.glassfish.jersey.tests.integration + 3.1.99-SNAPSHOT + + 4.0.0 + + jersey-6044 + + + + org.glassfish.jersey.containers + jersey-container-jetty-http + ${project.version} + test + + + org.eclipse.jetty + jetty-server + ${jetty.version} + test + + + org.eclipse.jetty.ee10 + jetty-ee10-servlet + ${jetty.version} + test + + + org.glassfish.jersey.test-framework.providers + jersey-test-framework-provider-bundle + pom + test + + + \ No newline at end of file diff --git a/tests/integration/jersey-6044/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource204.java b/tests/integration/jersey-6044/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource204.java new file mode 100644 index 00000000000..d5f27fdf203 --- /dev/null +++ b/tests/integration/jersey-6044/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource204.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jettyresponseclose; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.container.AsyncResponse; +import jakarta.ws.rs.container.Suspended; +import jakarta.ws.rs.core.Response; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +@Path("/get-me-204") +public class Resource204 { + private static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(100); + + @GET + public void get(@Suspended final AsyncResponse ar) { + executor.schedule(() -> { + ar.resume(Response.noContent().build()); + }, 50, TimeUnit.MILLISECONDS); + } +} diff --git a/tests/integration/jersey-6044/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerDuringShutdownTest.java b/tests/integration/jersey-6044/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerDuringShutdownTest.java new file mode 100644 index 00000000000..c81817556c7 --- /dev/null +++ b/tests/integration/jersey-6044/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerDuringShutdownTest.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jettyresponseclose; + +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.core.Response; +import org.eclipse.jetty.ee10.servlet.ServletContextHandler; +import org.eclipse.jetty.ee10.servlet.ServletHolder; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.handler.ContextHandlerCollection; +import org.eclipse.jetty.server.handler.StatisticsHandler; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.servlet.ServletContainer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +public class JettyHttpContainerDuringShutdownTest { + + private static Server server; + private static final String URL = "http://localhost:9080/test/get-me-204"; + + @BeforeAll + public static void setup() throws Exception { + ResourceConfig resourceConfig = new ResourceConfig(Collections.singleton(Resource204.class)); + ServletContextHandler ctx = new ServletContextHandler(); + ServletHolder servlet = new ServletHolder(new ServletContainer(resourceConfig)); + ctx.addServlet(servlet, "/test/*"); + ContextHandlerCollection handlers = new ContextHandlerCollection(); + server = new Server(); + + handlers.addHandler(ctx); + StatisticsHandler statisticsHandler = new StatisticsHandler(); + statisticsHandler.setHandler(handlers); + server.setHandler(statisticsHandler); + + ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(new HttpConfiguration())); + http.setPort(9080); + server.addConnector(http); + server.setStopTimeout(50); + server.start(); + + waitStartUp(); + } + + private static void waitStartUp() { + for (int i = 0; i < 10; i++) { + try { + Response response = ClientBuilder.newClient().target(URL).request().get(); + if (response.getStatus() == 204) { + return; + } + } catch (Throwable ignore) { + } + } + } + + @AfterAll + public static void shutdown() throws Exception { + if (server != null) { + try { + server.stop(); + server = null; + } catch (Throwable ignore) { + } + } + } + + @Test + public void testResponseClose() throws Exception { + Client client = ClientBuilder.newClient(); + try { + List> waitingResponses = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + waitingResponses.add(client.target(URL).request().async().get()); + } + shutdown(); + for (Future responseFuture : waitingResponses) { + Response response = responseFuture.get(30, TimeUnit.SECONDS); + response.close(); + Assertions.assertNotEquals(200, response.getStatus()); + if (response.getStatus() / 100 != 2 && response.getStatus() / 100 != 5) { + Assertions.fail("Unexpected response code: " + response.getStatus()); + } + } + } finally { + try { + client.close(); + } catch (Throwable ignored) { + } + } + } +} diff --git a/tests/integration/jersey-6044/src/test/resources/surefire.policy b/tests/integration/jersey-6044/src/test/resources/surefire.policy new file mode 100644 index 00000000000..f012633e76b --- /dev/null +++ b/tests/integration/jersey-6044/src/test/resources/surefire.policy @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +// we do not care about java lib itself +grant codebase "file:${java.home}/-" { + permission java.security.AllPermission; +}; + +// we do not care about our dependencies +grant codebase "file:${settings.localRepository}/-" { + permission java.security.AllPermission; +}; + +grant codebase "file:${user.home}/-" { + permission java.io.FilePermission "<>", "read"; +}; + +grant { + permission java.lang.management.ManagementPermission "monitor"; + permission java.util.PropertyPermission "*", "read, write"; + permission java.util.logging.LoggingPermission "control"; + permission java.lang.RuntimePermission "setIO"; + permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; + + permission java.lang.RuntimePermission "accessDeclaredMembers"; + permission java.lang.RuntimePermission "modifyThread"; + permission java.io.FilePermission "<>", "read"; + + permission java.lang.RuntimePermission "getenv.JETTY_AVAILABLE_PROCESSORS"; + permission java.net.SocketPermission "localhost", "accept,connect,listen,resolve"; + permission java.lang.RuntimePermission "setContextClassLoader"; +}; diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml index 49fc4386657..ce5b50feffe 100644 --- a/tests/integration/pom.xml +++ b/tests/integration/pom.xml @@ -60,6 +60,7 @@ jersey-4722 jersey-5087 jersey-5796 + jersey-6044 microprofile property-check reactive-streams @@ -161,6 +162,7 @@ jersey-2892 jersey-3796 jersey-4949 + jersey-6044 resteasy-client security-digest servlet-2.5-autodiscovery-1 From 3a464930712730602a5761c0a86ce4d14922fd2c Mon Sep 17 00:00:00 2001 From: guerrillakg Date: Mon, 4 May 2026 15:59:40 +0200 Subject: [PATCH 2/3] 6044 Do not complete requests on receiving notification events --- .../AsyncContextDelegateProviderImpl.java | 2 +- tests/integration/jersey-6044/pom.xml | 18 ++++++++++++++++++ .../tests/jettyresponseclose/Resource204.java | 2 +- .../JettyHttpContainerDuringShutdownTest.java | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/containers/jersey-servlet/src/main/java/org/glassfish/jersey/servlet/async/AsyncContextDelegateProviderImpl.java b/containers/jersey-servlet/src/main/java/org/glassfish/jersey/servlet/async/AsyncContextDelegateProviderImpl.java index 5758199047e..6597e84e482 100644 --- a/containers/jersey-servlet/src/main/java/org/glassfish/jersey/servlet/async/AsyncContextDelegateProviderImpl.java +++ b/containers/jersey-servlet/src/main/java/org/glassfish/jersey/servlet/async/AsyncContextDelegateProviderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2025 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2026 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at diff --git a/tests/integration/jersey-6044/pom.xml b/tests/integration/jersey-6044/pom.xml index 9454fa7c27d..2ed6edca0e2 100644 --- a/tests/integration/jersey-6044/pom.xml +++ b/tests/integration/jersey-6044/pom.xml @@ -1,4 +1,22 @@ + + diff --git a/tests/integration/jersey-6044/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource204.java b/tests/integration/jersey-6044/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource204.java index d5f27fdf203..4171bcdcd04 100644 --- a/tests/integration/jersey-6044/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource204.java +++ b/tests/integration/jersey-6044/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource204.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at diff --git a/tests/integration/jersey-6044/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerDuringShutdownTest.java b/tests/integration/jersey-6044/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerDuringShutdownTest.java index c81817556c7..dd2515fc181 100644 --- a/tests/integration/jersey-6044/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerDuringShutdownTest.java +++ b/tests/integration/jersey-6044/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerDuringShutdownTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at From 518693c9fadc61687c9ecfe393908475dcc8bdde Mon Sep 17 00:00:00 2001 From: guerrillakg Date: Fri, 8 May 2026 12:51:01 +0200 Subject: [PATCH 3/3] 6044 Do not complete requests on receiving notification events --- .../integration/jersey-6044/src/test/resources/surefire.policy | 2 +- tests/integration/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/jersey-6044/src/test/resources/surefire.policy b/tests/integration/jersey-6044/src/test/resources/surefire.policy index f012633e76b..02ed408a421 100644 --- a/tests/integration/jersey-6044/src/test/resources/surefire.policy +++ b/tests/integration/jersey-6044/src/test/resources/surefire.policy @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml index ce5b50feffe..4d731b4131f 100644 --- a/tests/integration/pom.xml +++ b/tests/integration/pom.xml @@ -1,7 +1,7 @@