Closed chanakaudaya closed 4 years ago
Ballerina http client by default enables response cache. Also currently released version of MGW doesn't support changing this behavior by configurations. As a workaround below is something you can try.
Add cache: { enabled: false }
manually to below line https://github.com/wso2/product-microgateway/blob/030fa555c968e392203c0e1fea98d2dbbbbeab4f/components/micro-gateway-cli/src/main/resources/templates/httpEndpoint.mustache#L3
Resulting file will look like,
http:Client {{qualifiedServiceName}}_{{endpointUrlType}} = new (
{{#if endpoints.0.isEtcdEnabled}}gateway:etcdSetup("{{name}}_{{endpointUrlType}}_endpoint_0","{{name}}_{{endpointUrlType}}_0_etcdKey","{{endpoints.0.endpointUrl}}","{{endpoints.0.etcdKey}}"){{else}}gateway:retrieveConfig("{{name}}_{{endpointUrlType}}_endpoint_0","{{endpoints.0.endpointUrl}}"){{/if}},
config = { cache: {enabled: false}, {{>http2}}{{>basicAuth}}{{>secureSocket}}
});
Upcoming version of MGW will support changing response caching behavior by extension. You can track progress with #929
I'm not sure whether you're answering the actual problem here. The problem I faced was a fundamental usability issue of the MGW.
This behavior stops me from using MGW. A few things, 1) I'm running MGW with the default config (by default, caching is enabled in MGW) 2) I haven't enabled response caching when creating the API
What is your suggestion for this scenario? Note: I have tried with enabling response caching on the API through the publisher and recreated the MGW, still the same error.
Let me explain my answer, By looking at the log you've attached it looks like this issues comes due to some issue in ballerina http client when response caching is enabled. When calling the backend endpoint of MGW API, we are using a ballerina http client which by default enables response caching. However for now you can't enabled or disable this behavior by extension or by changing config in WSO2 API Publisher. Which means API Publisher configuration on the response caching doesn't take effect in MGW.
So with the assumption this is caused by this default response cache behavior of ballerina http client, I suggested above workaround for you to disable the response cache and check the behavior. If that works for you we can try to confirm if it is already fixed in the latest master after jballerina upgrade.
I'm sorry, I didn't understand your workaround properly. Is this a configuration change in the product or changing the source code of the product and recompile?
Oops sorry my bad. Forgot to mention the file to update.
You can find above file in <TOOLKIT_HOME>/resources/templates/httpEndpoint.mustache
.
To make this change available for all endpoint types you can change <TOOLKIT_HOME>/resources/templates/caching.mustache
and replace file content with below.
, cache: { enabled: false }
This suggestion worked. I'm able to get the correct response to subsequent requests.
<TOOLKIT_HOME>/resources/templates/caching.mustache
file content to the below content
http:Client {{qualifiedServiceName}}_{{endpointUrlType}} = new (
{{#if endpoints.0.isEtcdEnabled}}gateway:etcdSetup("{{name}}_{{endpointUrlType}}_endpoint_0","{{name}}_{{endpointUrlType}}_0_etcdKey","{{endpoints.0.endpointUrl}}","{{endpoints.0.etcdKey}}"){{else}}gateway:retrieveConfig("{{name}}_{{endpointUrlType}}_endpoint_0","{{endpoints.0.endpointUrl}}"){{/if}},
config = { cache: {enabled: false}, {{>http2}}{{>caching}}{{>basicAuth}}{{>secureSocket}}
});
Closing since issue is tracked via #929
Description:
I'm getting an error when sending back to back requests to the microgateway. The first request works fine. I get the below error when I send the subsequent request.
Steps to reproduce:
I'm using the APIM 3.0 to develop the API and then import that to MGW 3.0.2 through the CLI. I have generated a token from the devportal and use that for invocation.
Everything goes well with the first request. The second request fails. If I try after a minute, it works again for the first req and failed the next one. Looks like a caching issue I tried enabling response caching on the API through the publisher, still, the issue persists
Affected Product Version:
APIM 3.0 MGW 3.0.2
Environment details (with versions):