[ 
https://issues.apache.org/jira/browse/KNOX-3058?focusedWorklogId=931144&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-931144
 ]

ASF GitHub Bot logged work on KNOX-3058:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 21/Aug/24 13:11
            Start Date: 21/Aug/24 13:11
    Worklog Time Spent: 10m 
      Work Description: pzampino commented on code in PR #929:
URL: https://github.com/apache/knox/pull/929#discussion_r1725029902


##########
gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java:
##########
@@ -717,6 +723,21 @@ void createJetty() throws IOException, 
CertificateException, NoSuchAlgorithmExce
     jetty.setAttribute(ContextHandler.MAX_FORM_KEYS_KEY, 
config.getJettyMaxFormKeys());
     log.setMaxFormKeys(config.getJettyMaxFormKeys());
 
+    // Add a handler for the 404 responses when a topology is being redeployed 
(i.e., is inactive)
+    jetty.setErrorHandler(new ErrorHandler() {
+      @Override
+      public void doError(String target, Request baseRequest, 
HttpServletRequest request, HttpServletResponse response) throws IOException {
+        final int gatewayPrefixLength = ("/" + config.getGatewayPath() + 
"/").length();
+        String pathInfo = baseRequest.getPathInfo();
+        String topologyName = pathInfo.substring(gatewayPrefixLength, 
pathInfo.indexOf('/', gatewayPrefixLength));
+        if (isInactiveTopology(topologyName) && (response.getStatus() == 
HttpServletResponse.SC_NOT_FOUND)) {
+          request.setAttribute("javax.servlet.error.message", "Service 
Unavailable"); // The default ErrorHandler references this attribute
+          response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);

Review Comment:
   We could certainly log that fact, but I think the error messages (e.g., 
Service Unavailable) are pretty standard. Given the separation between status 
code and error message though, I could be persuaded otherwise.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 931144)
    Time Spent: 1h 20m  (was: 1h 10m)

> Avoid 404 When Topology Is Being Redeployed
> -------------------------------------------
>
>                 Key: KNOX-3058
>                 URL: https://issues.apache.org/jira/browse/KNOX-3058
>             Project: Apache Knox
>          Issue Type: Improvement
>          Components: Server
>            Reporter: Philip Zampino
>            Assignee: Philip Zampino
>            Priority: Major
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> While a topology is being redeployed, if it is requested, the client receives 
> an HTTP 404 response. Most clients will not retry when receiving a 404, so 
> the interaction will fail.
> If Knox were to respond with a more retry-friendly response (e.g., HTTP 503), 
> then clients could overcome these small windows of unavailability with 
> retries.
> The difficult part may be distinguishing topology removal from topology 
> inactivity. I think a deleted topology should still result in a 404.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to