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

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

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


##########
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:
   Just a thought, can we specify in the error message that the topology is 
inactive? This will be helpful in cases where we are debugging and knox the 
request failed because topology was inactive and not due to 500 error.
   





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

    Worklog Id:     (was: 931040)
    Time Spent: 1h  (was: 50m)

> 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
>  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