Skip to content

Commit

Permalink
Merge pull request #1021 from 3scale/fix-incorrect-connection-reuse
Browse files Browse the repository at this point in the history
[THREESCALE-2205] Fix incorrect connection reuse
  • Loading branch information
davidor authored Apr 25, 2019
2 parents 9a467d7 + 5d683c1 commit 773bb91
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Fixed incorrect description of the `client` attribute in the Keycloak role check policy [PR #1005](https://github.com/3scale/APIcast/pull/1005), [THREESCALE_1867](https://issues.jboss.org/browse/THREESCALE-1867)
- Segfault when normalizing some client certificates [PR #1006](https://github.com/3scale/APIcast/pull/1006)
- Fixed incorrect connection reuse for requests on different domains [PR #1021](https://github.com/3scale/APIcast/pull/1021), [THREESCALE-2205](https://issues.jboss.org/browse/THREESCALE-2205)

### Removed

Expand Down
4 changes: 3 additions & 1 deletion gateway/src/resty/http/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ local function connect_direct(httpc, request)
local uri = request.uri
local host = uri.host
local ip, port = httpc:resolve(host, nil, uri)
local ok, err = httpc:connect(ip, port or default_port(uri))

local options = { pool = format('%s:%s', host, port) }
local ok, err = httpc:connect(ip, port or default_port(uri), options)

if not ok then return nil, err end

Expand Down
42 changes: 42 additions & 0 deletions spec/resty/http/proxy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,47 @@ describe('resty.http.proxy', function()
assert.same(200, res.status)
assert.match('GET http://127.0.0.1:1984/request HTTP/1.1', res:read_body())
end)

-- Regression test. Ref: https://issues.jboss.org/browse/THREESCALE-2205
context('when different subdomains resolve to the same IP', function()
local request_domain_1 = { url = 'http://test.example.com/', method = 'GET' }
local request_domain_2 = { url = 'http://prod.example.com/', method = 'GET' }

before_each(function()
-- Make everything resolve to the same IP
local resty_resolver = require 'resty.resolver.http'
stub(resty_resolver, 'resolve', function() return "1.1.1.1", 80 end)
end)

context('and it uses a http proxy', function()
before_each(function()
_M:reset({ http_proxy = 'http://127.0.0.1:1984' })
end)

it('does not reuse the connection', function()
local proxy = _M.new(request_domain_1)
proxy:request(request_domain_1):read_body()
proxy:set_keepalive()

proxy = _M.new(request_domain_2)
assert.same(0, proxy:get_reused_times())
end)
end)

context('and it does not use an http proxy', function()
before_each(function()
_M:reset({})
end)

it('does not reuse the connection', function()
local proxy = _M.new(request_domain_1)
proxy:request(request_domain_1):read_body()
proxy:set_keepalive()

proxy = _M.new(request_domain_2)
assert.same(0, proxy:get_reused_times())
end)
end)
end)
end)
end)

0 comments on commit 773bb91

Please sign in to comment.