Skip to content

Commit 77e2f4c

Browse files
committed
Don't stop crashed apps while shutting down
1 parent 79842f9 commit 77e2f4c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/java/eu/openanalytics/containerproxy/util/ProxyMappingManager.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import io.undertow.util.PathMatcher;
4343
import org.springframework.context.annotation.Lazy;
4444
import io.undertow.util.StatusCodes;
45+
import org.springframework.context.event.ContextClosedEvent;
46+
import org.springframework.context.event.EventListener;
4547
import org.springframework.stereotype.Component;
4648

4749
import javax.inject.Inject;
@@ -74,7 +76,9 @@ public class ProxyMappingManager {
7476
private PathHandler pathHandler;
7577

7678
private final Map<String, String> mappings = new HashMap<>();
77-
79+
80+
private volatile boolean isShuttingDown = false;
81+
7882
@Inject
7983
@Lazy
8084
private HeartbeatService heartbeatService;
@@ -172,6 +176,11 @@ public void dispatchAsync(String proxyId, String mapping, HttpServletRequest req
172176
request.getRequestDispatcher(targetPath).forward(request, response);
173177
}
174178

179+
@EventListener(ContextClosedEvent.class)
180+
public void onApplicationEvent(ContextClosedEvent event) {
181+
isShuttingDown = true;
182+
}
183+
175184
private final DefaultResponseListener defaultResponseListener = responseExchange -> {
176185
if (!responseExchange.isResponseChannelAvailable()) {
177186
return false;
@@ -182,7 +191,7 @@ public void dispatchAsync(String proxyId, String mapping, HttpServletRequest req
182191
if (proxyIdAttachment != null) {
183192
try {
184193
proxy = proxyService.getProxy(proxyIdAttachment.proxyId);
185-
if (proxy != null && !proxy.getStatus().isUnavailable()) {
194+
if (proxy != null && !proxy.getStatus().isUnavailable() && !isShuttingDown) {
186195
logger.info(proxy, "Proxy unreachable/crashed, stopping it now");
187196
asyncProxyService.stopProxy(proxy, true);
188197
}

0 commit comments

Comments
 (0)