Skip to content

Commit 835d6e3

Browse files
committed
Merge pull request #1021 from 3scale/fix-incorrect-connection-reuse
[THREESCALE-2205] Fix incorrect connection reuse
1 parent 706cdbc commit 835d6e3

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
## Fixed
1414

1515
- Segfault when normalizing some client certificates [PR #1006](https://github.com/3scale/APIcast/pull/1006)
16+
- 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)
1617

1718
## [3.5.0] - 2019-05-07
1819

gateway/src/resty/http/proxy.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ local function connect_direct(httpc, request)
1717
local uri = request.uri
1818
local host = uri.host
1919
local ip, port = httpc:resolve(host, nil, uri)
20-
local ok, err = httpc:connect(ip, port or default_port(uri))
20+
21+
local options = { pool = format('%s:%s', host, port) }
22+
local ok, err = httpc:connect(ip, port or default_port(uri), options)
2123

2224
if not ok then return nil, err end
2325

spec/resty/http/proxy_spec.lua

+42
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,47 @@ describe('resty.http.proxy', function()
5858
assert.same(200, res.status)
5959
assert.match('GET http://127.0.0.1:1984/request HTTP/1.1', res:read_body())
6060
end)
61+
62+
-- Regression test. Ref: https://issues.jboss.org/browse/THREESCALE-2205
63+
context('when different subdomains resolve to the same IP', function()
64+
local request_domain_1 = { url = 'http://test.example.com/', method = 'GET' }
65+
local request_domain_2 = { url = 'http://prod.example.com/', method = 'GET' }
66+
67+
before_each(function()
68+
-- Make everything resolve to the same IP
69+
local resty_resolver = require 'resty.resolver.http'
70+
stub(resty_resolver, 'resolve', function() return "1.1.1.1", 80 end)
71+
end)
72+
73+
context('and it uses a http proxy', function()
74+
before_each(function()
75+
_M:reset({ http_proxy = 'http://127.0.0.1:1984' })
76+
end)
77+
78+
it('does not reuse the connection', function()
79+
local proxy = _M.new(request_domain_1)
80+
proxy:request(request_domain_1):read_body()
81+
proxy:set_keepalive()
82+
83+
proxy = _M.new(request_domain_2)
84+
assert.same(0, proxy:get_reused_times())
85+
end)
86+
end)
87+
88+
context('and it does not use an http proxy', function()
89+
before_each(function()
90+
_M:reset({})
91+
end)
92+
93+
it('does not reuse the connection', function()
94+
local proxy = _M.new(request_domain_1)
95+
proxy:request(request_domain_1):read_body()
96+
proxy:set_keepalive()
97+
98+
proxy = _M.new(request_domain_2)
99+
assert.same(0, proxy:get_reused_times())
100+
end)
101+
end)
102+
end)
61103
end)
62104
end)

0 commit comments

Comments
 (0)