Skip to content

Commit

Permalink
Merge pull request #79 from GoogleCloudPlatform:HttpStreamWrapper
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 580932773
Change-Id: I6741c74d7f10411cb184d97b0930797d93731929
  • Loading branch information
gae-java-bot committed Nov 9, 2023
2 parents 55e72c9 + f5b665f commit 6e81c98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,12 @@ public Future<byte[]> 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);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.4.53.v20231009</jetty.version>
<jetty12.version>12.0.2</jetty12.version>
<jetty12.version>12.0.3</jetty12.version>
<slf4j.version>2.0.9</slf4j.version>
<distributionManagement.snapshot.url>https://oss.sonatype.org/content/repositories/google-snapshots/</distributionManagement.snapshot.url>
<distributionManagement.snapshot.id>sonatype-nexus-snapshots</distributionManagement.snapshot.id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6e81c98

Please sign in to comment.