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

WFLY-4736 - Don't use MSC thread to start web components from within UndertowDeploymentService #7574

Merged
merged 1 commit into from Jun 4, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -35,6 +35,7 @@
import org.jboss.as.security.plugins.SecurityDomainContext;
import org.jboss.as.security.service.JaccService;
import org.jboss.as.security.service.SecurityDomainService;
import org.jboss.as.server.Services;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentResourceSupport;
Expand Down Expand Up @@ -346,6 +347,9 @@ private void processDeployment(final WarMetaData warMetaData, final DeploymentUn
.addDependency(hostServiceName, Host.class, service.getHost())
.addDependencies(deploymentUnit.getAttachmentList(Attachments.WEB_DEPENDENCIES))
.addDependency(deploymentInfoServiceName, DeploymentInfo.class, service.getDeploymentInfoInjectedValue());
// inject the server executor which can be used by the WebDeploymentService for blocking tasks in start/stop
// of that service
Services.addServerExecutorDependency(builder, service.getServerExecutorInjector(), false);

deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES, deploymentServiceName);

Expand Down
Expand Up @@ -23,6 +23,7 @@
package org.wildfly.extension.undertow.deployment;

import java.io.File;
import java.util.concurrent.ExecutorService;

import io.undertow.server.HttpHandler;
import io.undertow.servlet.api.Deployment;
Expand All @@ -36,6 +37,7 @@
import org.jboss.as.web.common.WebInjectionContainer;
import org.jboss.as.web.host.ContextActivator;
import org.jboss.el.cache.FactoryFinderCache;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.StartContext;
Expand All @@ -52,6 +54,8 @@
public class UndertowDeploymentService implements Service<UndertowDeploymentService> {

private final InjectedValue<ServletContainerService> container = new InjectedValue<>();
// used for blocking tasks in this Service's start/stop
private final InjectedValue<ExecutorService> serverExecutor = new InjectedValue<ExecutorService>();
private final WebInjectionContainer webInjectionContainer;
private final InjectedValue<Host> host = new InjectedValue<>();
private final InjectedValue<DeploymentInfo> deploymentInfoInjectedValue = new InjectedValue<>();
Expand All @@ -67,11 +71,21 @@ public UndertowDeploymentService(final WebInjectionContainer webInjectionContain
@Override
public void start(final StartContext startContext) throws StartException {
if (autostart) {
try {
startContext();
} catch (ServletException e) {
throw new StartException(e);
}
// The start can trigger the web app context initialization which involves blocking tasks like
// servlet context initialization, startup servlet initialization lifecycles and such. Hence this needs to be done asynchronously
// to prevent the MSC threads from blocking
startContext.asynchronous();
serverExecutor.getValue().submit(new Runnable() {
@Override
public void run() {
try {
startContext();
startContext.complete();
} catch (Throwable e) {
startContext.failed(new StartException(e));
}
}
});
}
}

Expand All @@ -97,7 +111,20 @@ public void startContext() throws ServletException {

@Override
public void stop(final StopContext stopContext) {
stopContext();
// The service stop can trigger the web app context destruction which involves blocking tasks like servlet context destruction, startup servlet
// destruction lifecycles and such. Hence this needs to be done asynchronously to prevent the MSC threads from blocking
stopContext.asynchronous();
serverExecutor.getValue().submit(new Runnable() {
@Override
public void run() {
try {
stopContext();
} finally {
stopContext.complete();
}
}
});

}

public void stopContext() {
Expand Down Expand Up @@ -145,6 +172,10 @@ public Deployment getDeployment(){
return deploymentManager.getDeployment();
}

Injector<ExecutorService> getServerExecutorInjector() {
return this.serverExecutor;
}

/**
* Provides an API to start/stop the {@link UndertowDeploymentService}.
* This should register/deregister the web context.
Expand Down