|
20 | 20 | */ |
21 | 21 | package eu.openanalytics.containerproxy.util; |
22 | 22 |
|
| 23 | +import eu.openanalytics.containerproxy.model.runtime.Proxy; |
| 24 | +import eu.openanalytics.containerproxy.model.runtime.ProxyStatus; |
23 | 25 | import eu.openanalytics.containerproxy.service.ProxyService; |
24 | 26 | import eu.openanalytics.containerproxy.service.hearbeat.HeartbeatService; |
25 | 27 | import io.undertow.io.Sender; |
@@ -152,20 +154,30 @@ public void dispatchAsync(String proxyId, String mapping, HttpServletRequest req |
152 | 154 | return false; |
153 | 155 | } |
154 | 156 | if (responseExchange.getStatusCode() == StatusCodes.SERVICE_UNAVAILABLE) { |
155 | | - final String errorPage = "{\"status\":\"error\", \"message\":\"app_crashed\"}"; |
156 | | - responseExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, "" + errorPage.length()); |
157 | | - responseExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json"); |
158 | | - Sender sender = responseExchange.getResponseSender(); |
159 | | - sender.send(errorPage); |
160 | | - |
161 | 157 | ProxyIdAttachment proxyIdAttachment = responseExchange.getAttachment(ATTACHMENT_KEY_PROXY_ID); |
| 158 | + Proxy proxy = null; |
162 | 159 | if (proxyIdAttachment != null) { |
163 | 160 | try { |
164 | | - proxyService.stopCrashedProxy(proxyIdAttachment.proxyId); |
| 161 | + proxy = proxyService.getProxy(proxyIdAttachment.proxyId); |
| 162 | + if (proxy != null) { |
| 163 | + proxyService.stopCrashedProxy(proxy); |
| 164 | + } |
165 | 165 | } catch (Throwable t) { |
166 | 166 | // ignore in order to complete request |
167 | 167 | } |
168 | 168 | } |
| 169 | + |
| 170 | + String errorPage; |
| 171 | + if (proxy != null && proxy.getStatus() != ProxyStatus.Stopped) { |
| 172 | + errorPage = "{\"status\":\"error\", \"message\":\"app_crashed\"}"; |
| 173 | + } else { |
| 174 | + // in-progress request got terminated because the app has been stopped (not crashed) |
| 175 | + errorPage = "{\"status\":\"error\", \"message\":\"app_stopped_or_non_existent\"}"; |
| 176 | + } |
| 177 | + responseExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, "" + errorPage.length()); |
| 178 | + responseExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json"); |
| 179 | + Sender sender = responseExchange.getResponseSender(); |
| 180 | + sender.send(errorPage); |
169 | 181 | return true; |
170 | 182 | } |
171 | 183 | return false; |
|
0 commit comments