Kong: [QUESTION] Is there way to disallow connection reusing (or generally inject custom nginx directives) for the specific upstream ?

Created on 24 Jun 2020  路  3Comments  路  Source: Kong/kong

Good day.

Is there possibility to prohibit using keep-alive connection with some specific upstream service?

Issue can be demonstrated and reproduced on a raw nginx with this gist: https://gist.github.com/Voronenko/ec3826b72b20c18410b26d4f5c0e2ccc

so - when kong first time connects to the external service to query for method1, it is somehow binded to some backend service responsible for handling method1, which serves it with success for any number of calls.

In case if I request method2 from the same api, it fails, because connection is reused, gets to the host responsible for serving method1, and thus failing to serve method2.

I can replace ordering, and call first method2, get binded initially to another service, which does not care about method1.

Decision most likely even can be done basing on a query string, i.e. I can't easily match by get request prefix in path.

In nginx I can "fix it" in a dirty way by forcing keepalive_requests 1 (from default 100) for the specific upstream.

Is there approach to do the same with kong (perhaps via configuration or using some plugin)? - Either prohibit connection reusing, or at least inject specific nginx configuration into upstream definition for that service.

Unfortunately, at a moment I have no control over external service with such behavior.

Thank you for the attention

corproxy tasneeds-investigation

Most helpful comment

This might be the basis for that: https://github.com/Kong/kong/pull/5771

In the future, we could implement per-Service (or per-Upstream) keepalive pools, allowing users to granularly enable/disable, or configure upstream keepalive pools as they wish.

So the hard work is already done, now we just need to add properties to service.

All 3 comments

This might be the basis for that: https://github.com/Kong/kong/pull/5771

In the future, we could implement per-Service (or per-Upstream) keepalive pools, allowing users to granularly enable/disable, or configure upstream keepalive pools as they wish.

So the hard work is already done, now we just need to add properties to service.

Any suggested workaround until this moment ?Getting keepalive_requests=1 on a global level via kong.conf provides too big penalty for unaffected services?

@Voronenko all the logic seems to be here:
https://github.com/Kong/kong/blob/next/kong/init.lua#L861-L890

Not that hard to modify to suit your needs (even before we add it to our configuration entities).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeremyjpj0916 picture jeremyjpj0916  路  59Comments

daviesf1 picture daviesf1  路  39Comments

ahmadnassri picture ahmadnassri  路  59Comments

marktopper picture marktopper  路  41Comments

noamelf picture noamelf  路  36Comments