From 1334cb36796dcaa46e2deb5b89401dd30dddb110 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 9 Nov 2023 17:16:19 +1100 Subject: [PATCH 1/3] Use HttpStream.Wrapper for completion listener in JettyContainerService Signed-off-by: Lachlan Roberts --- .../jetty/ee10/JettyContainerService.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/runtime/local_jetty12_ee10/src/main/java/com/google/appengine/tools/development/jetty/ee10/JettyContainerService.java b/runtime/local_jetty12_ee10/src/main/java/com/google/appengine/tools/development/jetty/ee10/JettyContainerService.java index 38660b73..b20ae2e9 100644 --- a/runtime/local_jetty12_ee10/src/main/java/com/google/appengine/tools/development/jetty/ee10/JettyContainerService.java +++ b/runtime/local_jetty12_ee10/src/main/java/com/google/appengine/tools/development/jetty/ee10/JettyContainerService.java @@ -57,6 +57,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -70,6 +71,7 @@ import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.HttpStream; import org.eclipse.jetty.server.NetworkTrafficServerConnector; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Response; @@ -626,7 +628,20 @@ public boolean handle(Request request, Response response, Callback callback) thr // this and so the Environment has not yet been created. ApiProxy.Environment oldEnv = enterScope(request); try { - callback = Callback.from(callback, () -> onComplete(contextRequest)); + request.addHttpStreamWrapper(s -> new HttpStream.Wrapper(s) + { + @Override + public void succeeded() { + onComplete(contextRequest); + super.succeeded(); + } + + @Override + public void failed(Throwable x) { + onComplete(contextRequest); + super.failed(x); + } + }); return super.handle(request, response, callback); } finally { From f80f69404a3ba14958e5ef0449d89ade10c73357 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 9 Nov 2023 17:16:29 +1100 Subject: [PATCH 2/3] update to Jetty 12.0.3 Signed-off-by: Lachlan Roberts --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5c9bef72..ed3fb28a 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ 1.8 UTF-8 9.4.53.v20231009 - 12.0.2 + 12.0.3 2.0.9 https://oss.sonatype.org/content/repositories/google-snapshots/ sonatype-nexus-snapshots From f5b665f6e33773035f4ef7c3adf7084cac19514a Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 9 Nov 2023 17:32:44 +1100 Subject: [PATCH 3/3] remove completed TODO in ApiProxyLocalImpl Signed-off-by: Lachlan Roberts --- .../appengine/tools/development/ApiProxyLocalImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api_dev/src/main/java/com/google/appengine/tools/development/ApiProxyLocalImpl.java b/api_dev/src/main/java/com/google/appengine/tools/development/ApiProxyLocalImpl.java index 900727db..9304d3b1 100644 --- a/api_dev/src/main/java/com/google/appengine/tools/development/ApiProxyLocalImpl.java +++ b/api_dev/src/main/java/com/google/appengine/tools/development/ApiProxyLocalImpl.java @@ -203,10 +203,12 @@ public Future makeAsyncCall( Semaphore semaphore = (Semaphore) environment.getAttributes().get( LocalEnvironment.API_CALL_SEMAPHORE); if (semaphore != null) { - // TODO: investigate why the acquire() locks when Sessions are configured in appengine-web.xml - // Maybe the semaphore has been released just before the app engine session manager starts - // saving the data in datastore. - semaphore.tryAcquire(); + try { + semaphore.acquire(); + } catch (InterruptedException ex) { + // We never do this, so just propagate it as a RuntimeException for now. + throw new RuntimeException("Interrupted while waiting on semaphore:", ex); + } } AsyncApiCall asyncApiCall = new AsyncApiCall(environment, packageName, methodName, requestBytes, semaphore);