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..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
@@ -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..2ed6edca0e2
--- /dev/null
+++ b/tests/integration/jersey-6044/pom.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+ 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..4171bcdcd04
--- /dev/null
+++ b/tests/integration/jersey-6044/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource204.java
@@ -0,0 +1,39 @@
+/*
+ * 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
+ * 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..dd2515fc181
--- /dev/null
+++ b/tests/integration/jersey-6044/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerDuringShutdownTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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
+ * 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..02ed408a421
--- /dev/null
+++ b/tests/integration/jersey-6044/src/test/resources/surefire.policy
@@ -0,0 +1,45 @@
+/*
+ * 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
+ * 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..4d731b4131f 100644
--- a/tests/integration/pom.xml
+++ b/tests/integration/pom.xml
@@ -1,7 +1,7 @@