Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HttpStream.Wrapper for completion listener in JettyContainerService #79

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading