42
42
import io .undertow .util .PathMatcher ;
43
43
import org .springframework .context .annotation .Lazy ;
44
44
import io .undertow .util .StatusCodes ;
45
+ import org .springframework .context .event .ContextClosedEvent ;
46
+ import org .springframework .context .event .EventListener ;
45
47
import org .springframework .stereotype .Component ;
46
48
47
49
import javax .inject .Inject ;
@@ -74,7 +76,9 @@ public class ProxyMappingManager {
74
76
private PathHandler pathHandler ;
75
77
76
78
private final Map <String , String > mappings = new HashMap <>();
77
-
79
+
80
+ private volatile boolean isShuttingDown = false ;
81
+
78
82
@ Inject
79
83
@ Lazy
80
84
private HeartbeatService heartbeatService ;
@@ -172,6 +176,11 @@ public void dispatchAsync(String proxyId, String mapping, HttpServletRequest req
172
176
request .getRequestDispatcher (targetPath ).forward (request , response );
173
177
}
174
178
179
+ @ EventListener (ContextClosedEvent .class )
180
+ public void onApplicationEvent (ContextClosedEvent event ) {
181
+ isShuttingDown = true ;
182
+ }
183
+
175
184
private final DefaultResponseListener defaultResponseListener = responseExchange -> {
176
185
if (!responseExchange .isResponseChannelAvailable ()) {
177
186
return false ;
@@ -182,7 +191,7 @@ public void dispatchAsync(String proxyId, String mapping, HttpServletRequest req
182
191
if (proxyIdAttachment != null ) {
183
192
try {
184
193
proxy = proxyService .getProxy (proxyIdAttachment .proxyId );
185
- if (proxy != null && !proxy .getStatus ().isUnavailable ()) {
194
+ if (proxy != null && !proxy .getStatus ().isUnavailable () && ! isShuttingDown ) {
186
195
logger .info (proxy , "Proxy unreachable/crashed, stopping it now" );
187
196
asyncProxyService .stopProxy (proxy , true );
188
197
}
0 commit comments