Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[THREESCALE-11321] Introduce APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS env var (2.15) #1515

Open
wants to merge 1 commit into
base: 3scale-2.15-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Add `APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS` to limit the number of requests a single keepalive socket can handle [PR #1496](https://github.com/3scale/APIcast/pull/1496) [THREESCALE-11321](https://issues.redhat.com/browse/THREESCALE-11321)

## [3.15.0] 2024-04-04

### Fixed
Expand Down
10 changes: 10 additions & 0 deletions doc/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,16 @@ connections.
By default Gateway does not enable it, and the keepalive timeout on nginx is set
to [75 seconds](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout)

### `APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS`

**Value:** positive integers
**Example:** "1"

Sets the maximum number of requests that one keepalive connection can serve.
After reaching the limit, the connection closes.

NOTE: This value affects connections opened by APIcast and will not have any
impact on requests proxied via APIcast.

### `APICAST_CACHE_STATUS_CODES`

Expand Down
22 changes: 22 additions & 0 deletions gateway/src/resty/resolver/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ local url_helper = require('resty.url_helper')
local format = string.format

local setmetatable = setmetatable
local resty_env = require 'resty.env'
local tonumber = tonumber
local keepalive_request = resty_env.get('APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS')

local _M = setmetatable({}, { __index = resty_http })

Expand Down Expand Up @@ -85,4 +88,23 @@ function _M.connect(self, options, ...)
return ok, err
end

function _M:set_keepalive()
if keepalive_request then
local count, err = resty_http.get_reused_times(self)
if err then
return nil, err
end
if count >= tonumber(keepalive_request) then
resty_http.close(self)
return true
end
end

local ok, err = resty_http.set_keepalive(self)
if not ok then
return nil, err
end
return true
end

return _M