Enforced timeout: hard_timeouts trouble


#1

Hi,

I am still evaluating this project, and I am having a hard time figuring out hard_timeouts (:wink:)

Basically, the backend Rest API I have to work with has resources where operations are usually quick, and others which may take some time (into the minutes). I need to adapt the timeouts to those.

I figured out that jsvm_timeout in tyk.conf can be used to globally set the timeout, and I have successfully used it. But I can not get the hard_timeouts working.

Neither setting a jsvm_timeout to a low value and hard_timeouts.timeout to a high value, nor setting a jsvm_timeout to a high value and hard_timeouts.timeout to a low value will do anything, I will always get the timeout at the global jsvm_timeout time.
Which one of those possibilities is the expected/correct configuration?

I am not sure if I am doing it correctly, so I am going to paste a part of my API .json file. Note that I am trying to use Enforced Timeouts with Virtual Endpoints in JSVM.

"versions": {
    "Default": {
        "name": "Default",
        "use_extended_paths": true,
        "extended_paths": {
            "virtual": [
                {
                    "response_function_name": "sessionhandler",
                    "function_source_type": "file",
                    "function_source_uri": "middleware/sessionhandler.js",
                    "path": "api",
                    "method": "GET",
                    "use_session": false
                }
            ],
            "hard_timeouts": [
                {
                    "path": "api",
                    "method": "GET",
                    "timeout": 3
                }
            ]
        }
    }
}

Does anyone have a hint what else to try or how it is supposed to be used? Unfortunately the documentation and examples do not show how to use it.

And an additional, related question: Is it possible to catch the timeout, or catch a timeout to a backend REST API, and send a custom error back to the user/frontend? It looks like I can not try/catch the global JSVM timeout.

Thank you very much :smile:

PS: Maybe it is important:

"proxy": {
    "listen_path": "/resttest/",
    "strip_listen_path": true
},

Tyk virtual endpoints are coming in at /resttest/api/…


#2

Hi!

You are right that hard timeouts do not work with JSVM, and plugins in general.
And the only way to specify a timeout in case of JSVM is to use the global option you mentioned.

If you want some custom timeout logic like this, I think you have to use Python or gRPC plugins, where you can use custom 3-rd party libraries.

Hope it helps!


#3

Hallo Herr Beyer, vielen Dank für Ihr Interesse an Tyk - kann ich mit anderen Themen weiterhelfen? Sie erreichen mich unter [email protected].
Bis dahin einen schönen und erfolgreichen Tag!
/mike goerlich