Skip to content

Commit

Permalink
Merge pull request payara#6848 from flowlogix/failed-deployment-cleanup
Browse files Browse the repository at this point in the history
FISH-9171 bugfix: prevent deployment failures from causing an undeployment failure and leaks
  • Loading branch information
Pandrex247 committed Sep 16, 2024
1 parent e5d74ab commit e1f837b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2303,9 +2303,9 @@ protected void addChild(Container child, boolean isProgrammatic,
Wrapper oldJspServlet = null;

// Allow webapp to override JspServlet inherited from global web.xml.
boolean isJspServlet = "jsp".equals(wrapperName);
boolean isJspServlet = Constants.JSP_SERVLET_NAME.equals(wrapperName);
if (isJspServlet) {
oldJspServlet = (Wrapper) findChild("jsp");
oldJspServlet = (Wrapper) findChild(Constants.JSP_SERVLET_NAME);
if (oldJspServlet != null) {
removeChild(oldJspServlet);
}
Expand Down Expand Up @@ -3238,7 +3238,7 @@ public void addInstanceListener(InstanceListener listener) {
public void addJspMapping(String pattern) {
String servletName = findServletMapping("*.jsp");
if (servletName == null) {
servletName = "jsp";
servletName = Constants.JSP_SERVLET_NAME;
}

if( findChild(servletName) != null) {
Expand Down Expand Up @@ -5766,6 +5766,8 @@ public synchronized void start() throws LifecycleException {
} catch (Throwable t) {
log.log(Level.SEVERE, LogFacade.STARTUP_CONTEXT_FAILED_EXCEPTION, getName());
try {
// ensure that all JSP resources are released in stop() method below
forceLoadJspServlet();
stop();
} catch (Throwable tt) {
log.log(Level.SEVERE, LogFacade.CLEANUP_FAILED_EXCEPTION, tt);
Expand Down Expand Up @@ -5951,7 +5953,11 @@ public synchronized void stop(boolean isShutdown)

if ((manager != null) && (manager instanceof Lifecycle)) {
if(manager instanceof StandardManager) {
((StandardManager)manager).stop(isShutdown);
try {
((StandardManager)manager).stop(isShutdown);
} catch (LifecycleException e) {
log.log(Level.INFO, e.getMessage());
}
} else {
((Lifecycle)manager).stop();
}
Expand Down Expand Up @@ -8132,4 +8138,20 @@ private File getExtractedMetaInfResourcePath(String path) {
}
return null;
}


/**
* Force loading of the JSP servlet. This is needed in case of
* initialization failure, so the JSP servlet would be unloaded properly
* and release all of its resources
*
* @throws ServletException
*/
private void forceLoadJspServlet() throws ServletException {
Container jspServlet = findChild(Constants.JSP_SERVLET_NAME);
if (jspServlet instanceof Wrapper) {
Wrapper jspServletWrapper = (Wrapper) jspServlet;
jspServletWrapper.load();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2022] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.web;

Expand Down Expand Up @@ -232,6 +232,9 @@ public class WebContainer implements org.glassfish.api.container.Container, Post
@Inject
private LoggingRuntime loggingRuntime;

@Inject
private Deployment deployment;

private final Map<String, WebConnector> connectorMap = new HashMap<>();

private EmbeddedWebContainer _embedded;
Expand Down Expand Up @@ -2058,7 +2061,7 @@ public void unloadWebModule(String contextRoot, String appName, String virtualSe
}
}

if (!hasBeenUndeployed) {
if (!hasBeenUndeployed && deployment.getCurrentDeploymentContext() == null) {
logger.log(Level.SEVERE, LogFacade.UNDEPLOY_ERROR, contextRoot);
}
}
Expand Down

0 comments on commit e1f837b

Please sign in to comment.