-
Notifications
You must be signed in to change notification settings - Fork 45
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
cleanup of the JettyServletEngineAdapters and JettyHttpProxy for Jetty 9.4 and 12 #309
Changes from all commits
6fac4e9
274ad9f
fb24250
8e3083f
98fb566
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
import org.eclipse.jetty.server.HttpConfiguration; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.ServerConnector; | ||
import org.eclipse.jetty.server.SizeLimitHandler; | ||
import org.eclipse.jetty.util.VirtualThreads; | ||
import org.eclipse.jetty.util.resource.Resource; | ||
import org.eclipse.jetty.util.resource.ResourceFactory; | ||
|
@@ -102,6 +103,7 @@ private static AppYaml getAppYaml(ServletEngineAdapter.Config runtimeOptions) { | |
|
||
@Override | ||
public void start(String serverInfo, ServletEngineAdapter.Config runtimeOptions) { | ||
boolean isHttpConnectorMode = Boolean.getBoolean(HTTP_CONNECTOR_MODE); | ||
QueuedThreadPool threadPool = | ||
new QueuedThreadPool(MAX_THREAD_POOL_THREADS, MIN_THREAD_POOL_THREADS); | ||
// Try to enable virtual threads if requested and on java21: | ||
|
@@ -118,27 +120,44 @@ public InvocationType getInvocationType() { | |
return InvocationType.BLOCKING; | ||
} | ||
}; | ||
rpcConnector = | ||
new DelegateConnector(server, "RPC") { | ||
@Override | ||
public void run(Runnable runnable) { | ||
// Override this so that it does the initial run in the same thread. | ||
// Currently, we block until completion in serviceRequest() so no point starting new | ||
// thread. | ||
runnable.run(); | ||
} | ||
}; | ||
server.addConnector(rpcConnector); | ||
|
||
// Don't add the RPC Connector if in HttpConnector mode. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hum. so we did that, what the side effect? 2 connectors and one not used? More memory used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably, but I don't think the memory saving here is that significant considering the |
||
if (!isHttpConnectorMode) { | ||
rpcConnector = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that the rpcConnector won't be needed for HTTP mode but with this change we are no longer initializating this field anymore for both modes. Any chance that it would cause an NPE below for HttpConnector when we actually service the request? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field is only ever used in |
||
new DelegateConnector(server, "RPC") { | ||
@Override | ||
public void run(Runnable runnable) { | ||
// Override this so that it does the initial run in the same thread. | ||
// Currently, we block until completion in serviceRequest() so no point starting new | ||
// thread. | ||
runnable.run(); | ||
} | ||
}; | ||
|
||
HttpConfiguration httpConfiguration = rpcConnector.getHttpConfiguration(); | ||
httpConfiguration.setSendDateHeader(false); | ||
httpConfiguration.setSendServerVersion(false); | ||
httpConfiguration.setSendXPoweredBy(false); | ||
if (LEGACY_MODE) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question there (hard to diff), LEGACY_MODE is still in both rpc and http connector, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes but for http connector it is done in |
||
httpConfiguration.setRequestCookieCompliance(CookieCompliance.RFC2965); | ||
httpConfiguration.setResponseCookieCompliance(CookieCompliance.RFC2965); | ||
httpConfiguration.setUriCompliance(UriCompliance.LEGACY); | ||
} | ||
|
||
Comment on lines
+137
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are your thoughts about movign all this to the constructor of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wrote the jetty-delegate code to be a generic mechansim not google specific things, which could potentially be applied to other protocols other than the google RPC, so that it could potentially be extracted out into Jetty to be maintained in the future. The interface with google code is done in the So I think adding compliance modes specific for the google usage should be here rather than in the |
||
server.addConnector(rpcConnector); | ||
} | ||
|
||
AppVersionHandlerFactory appVersionHandlerFactory = | ||
AppVersionHandlerFactory.newInstance(server, serverInfo); | ||
appVersionHandler = new AppVersionHandler(appVersionHandlerFactory); | ||
if (!Boolean.getBoolean(IGNORE_RESPONSE_SIZE_LIMIT)) { | ||
CoreSizeLimitHandler sizeLimitHandler = new CoreSizeLimitHandler(-1, MAX_RESPONSE_SIZE); | ||
sizeLimitHandler.setHandler(appVersionHandler); | ||
server.setHandler(sizeLimitHandler); | ||
} else { | ||
server.setHandler(appVersionHandler); | ||
server.setHandler(appVersionHandler); | ||
|
||
// In HttpConnector mode we will combine both SizeLimitHandlers. | ||
boolean ignoreResponseSizeLimit = Boolean.getBoolean(IGNORE_RESPONSE_SIZE_LIMIT); | ||
if (!ignoreResponseSizeLimit && !isHttpConnectorMode) { | ||
server.insertHandler(new SizeLimitHandler(-1, MAX_RESPONSE_SIZE)); | ||
} | ||
|
||
boolean startJettyHttpProxy = false; | ||
if (runtimeOptions.useJettyHttpProxy()) { | ||
AppInfoFactory appInfoFactory; | ||
|
@@ -159,14 +178,13 @@ public void run(Runnable runnable) { | |
} catch (Exception e) { | ||
throw new IllegalStateException(e); | ||
} | ||
if (Boolean.getBoolean(HTTP_CONNECTOR_MODE)) { | ||
if (isHttpConnectorMode) { | ||
logger.atInfo().log("Using HTTP_CONNECTOR_MODE to bypass RPC"); | ||
JettyHttpProxy.insertHandlers(server); | ||
server.insertHandler( | ||
new JettyHttpHandler( | ||
runtimeOptions, appVersionHandler.getAppVersion(), appVersionKey, appInfoFactory)); | ||
ServerConnector connector = JettyHttpProxy.newConnector(server, runtimeOptions); | ||
server.addConnector(connector); | ||
JettyHttpProxy.insertHandlers(server, ignoreResponseSizeLimit); | ||
server.addConnector(JettyHttpProxy.newConnector(server, runtimeOptions)); | ||
} else { | ||
server.setAttribute( | ||
"com.google.apphosting.runtime.jetty.appYaml", | ||
|
@@ -197,7 +215,7 @@ public void stop() { | |
} | ||
|
||
@Override | ||
public void addAppVersion(AppVersion appVersion) throws FileNotFoundException { | ||
public void addAppVersion(AppVersion appVersion) { | ||
appVersionHandler.addAppVersion(appVersion); | ||
} | ||
|
||
|
@@ -239,16 +257,7 @@ public void serviceRequest(UPRequest upRequest, MutableUpResponse upResponse) th | |
} | ||
lastAppVersionKey = appVersionKey; | ||
} | ||
// TODO: lots of compliance modes to handle. | ||
HttpConfiguration httpConfiguration = rpcConnector.getHttpConfiguration(); | ||
httpConfiguration.setSendDateHeader(false); | ||
httpConfiguration.setSendServerVersion(false); | ||
httpConfiguration.setSendXPoweredBy(false); | ||
if (LEGACY_MODE) { | ||
httpConfiguration.setRequestCookieCompliance(CookieCompliance.RFC2965); | ||
httpConfiguration.setResponseCookieCompliance(CookieCompliance.RFC2965); | ||
httpConfiguration.setUriCompliance(UriCompliance.LEGACY); | ||
} | ||
|
||
DelegateRpcExchange rpcExchange = new DelegateRpcExchange(upRequest, upResponse); | ||
rpcExchange.setAttribute(AppEngineConstants.APP_VERSION_KEY_REQUEST_ATTR, appVersionKey); | ||
rpcExchange.setAttribute(AppEngineConstants.ENVIRONMENT_ATTR, ApiProxy.getCurrentEnvironment()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that fix the flakiness seen with 12.0.15 #304 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think so, I compared both
SizeLimitHandler
s and they were essentially the same other than some improved error handling in the Jetty one.Opened #310 to track this.