fix: avoid 404 and 500 error during api redeploy or stop
Closes gravitee-io/issues#6553
@@ -125,9 +125,10 @@ public class DefaultReactorHandlerRegistry implements ReactorHandlerRegistry {
if (newHandler != null) {
ReactorHandler previousHandler = handlers.remove(reactable);
List<HandlerEntrypoint> previousEntrypoints = entrypointByReactable.remove(previousHandler.reactable());
- registeredEntrypoints.removeIf(previousEntrypoints::contains);
+ // Register the new handler before removing the previous entrypoints to avoid 404, especially on high throughput.
register(newHandler);
+ registeredEntrypoints.removeIf(previousEntrypoints::contains);
try {
logger.debug("Stopping previous handler for: {}", reactable);
@@ -161,9 +162,11 @@ public class DefaultReactorHandlerRegistry implements ReactorHandlerRegistry {
private void remove(Reactable reactable, ReactorHandler handler, boolean remove) {
if (handler != null) {
try {
- handler.stop();
List<HandlerEntrypoint> previousEntrypoints = entrypointByReactable.remove(handler.reactable());
+
+ // Remove the entrypoints before stopping the handler to avoid 500 errors.
registeredEntrypoints.removeIf(previousEntrypoints::contains);
+ handler.stop();
if (remove) {
handlers.remove(reactable);
