krakend / krakend-ce

KrakenD Community Edition: High-performance, stateless, declarative, API Gateway written in Go.

Home Page:https://www.krakend.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Responses are still cached when JSON encoding fails

Holyriss opened this issue · comments

Environment info:

  • KrakenD version: 2.6.2
  • System info: docker

Describe the bug

When JSON encoding fails, the response is still cached by the http-cache plugin.

Exemple : a backend that returns a malformed JSON leads to a "Unexpected EOF" error message. This error will be cached (if the cache was empty)

Your configuration file:

{
  "version": 3,
  "$schema": "https://www.krakend.io/schema/v3.json",
  "timeout": "10s",
  "debug_endpoint": false,
  "extra_config": {
    "security/cors": {
      "allow_origins": ["*"],
      "allow_headers": ["*"],
      "allow_methods": [
        "GET",
        "HEAD",
        "POST",
        "OPTIONS",
        "PUT",
        "PATCH",
        "DELETE"
      ]
    },
    "router": {
      "return_error_msg": true
    }
  },
  "endpoints": [
    {
      "endpoint": "/test",
      "method": "GET",
      "input_headers": ["Authorization"],
      "input_query_strings": ["*"],
      "output_encoding": "json",
      "backend": [
        {
          "url_pattern": "/endpoint-that-could-returns-malformed-json",
          "host": ["http://localhost:8080"],
          "extra_config": {
            "qos/http-cache": { "shared": true },
            "modifier/martian": {
              "header.Modifier": {
                "scope": ["response"],
                "name": "Cache-Control",
                "value": "max-age=60, public"
              }
            }
          }
        }
      ]
    }
  ]
}

Commands used
None, it can be reproduced with krakend:watch docker image

Expected behavior.
Actually, if the backend returns an invalid status, the response is not cached.
That's the expected behavior when the encoding fails.

Additional context
We tried some workarounds, like using lua scripting and no-op output encoding, but none was working.

Hi, thank you for bringing this issue to our attention.

Many factors influence our product roadmaps and determine the features, fixes, and suggestions we implement.
When deciding what to prioritize and work on, we combine your feedback and suggestions with insights from our development team, product analytics, research findings, and more.

This information, combined with our product vision, determines what we implement and its priority order. Unfortunately, we don't foresee this issue progressing any further in the short-medium term, and we are closing it.

While this issue is now closed, we continue monitoring requests for our future roadmap, including this one.

If you have additional information you would like to provide, please share.


This is an automated comment. Responding to the bot or mentioning it won't have any effect