forked from Kong/lua-resty-healthcheck
-
Notifications
You must be signed in to change notification settings - Fork 8
fix: clean every checker each window and release periodic lock when idle #55
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
Open
AlinsRan
wants to merge
11
commits into
master
Choose a base branch
from
fix/cleanup-gating-and-lock-scope
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ada5ee8
fix: clean every checker each window and release lock when idle
AlinsRan df219d2
test: cover periodic-lock release and mirror cleanup test to resty-ev…
AlinsRan 941ca86
test: disable externally-dependent 14-tls active-probe test
AlinsRan 76ab8fb
fix: only contend for the periodic lock when a checker is active
AlinsRan 38d86b3
test: make TLS active-probe and status-version tests deterministic
AlinsRan 356d122
fix: decouple stale-target cleanup from active-checker gating
AlinsRan ae3e2f9
test: normalize has-active boolean in passive-only cleanup test
AlinsRan ea63000
fix: elect one cleanup worker per window and resume probing promptly
AlinsRan 8c71840
test: bound the cross-worker barrier wait in 99-status_ver
AlinsRan 24ea30c
fix: drop ineffective timer-wake on checker re-enable
AlinsRan 6532665
refactor: drop no-op active_check_timer.interval back-off assignments
AlinsRan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| use Test::Nginx::Socket::Lua; | ||
| use Cwd qw(cwd); | ||
|
|
||
| workers(1); | ||
|
|
||
| plan tests => repeat_each() * (blocks() * 2); | ||
|
|
||
| my $pwd = cwd(); | ||
| $ENV{TEST_NGINX_SERVROOT} = server_root(); | ||
|
|
||
| our $HttpConfig = qq{ | ||
| lua_package_path "$pwd/lib/?.lua;;"; | ||
| lua_shared_dict test_shm 8m; | ||
|
|
||
| init_worker_by_lua_block { | ||
| _G.__TESTING_HEALTHCHECKER = true | ||
| local we = require "resty.events.compat" | ||
| assert(we.configure({ | ||
| unique_timeout = 5, | ||
| broker_id = 0, | ||
| listening = "unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock" | ||
| })) | ||
| assert(we.configured()) | ||
| } | ||
|
|
||
| server { | ||
| server_name kong_worker_events; | ||
| listen unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock; | ||
| access_log off; | ||
| location / { | ||
| content_by_lua_block { | ||
| require("resty.events.compat").run() | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| run_tests(); | ||
|
|
||
| __DATA__ | ||
|
|
||
| === TEST 1: stale-target cleanup runs for every checker, not just the first one | ||
| --- http_config eval: $::HttpConfig | ||
| --- config | ||
| location = /t { | ||
| content_by_lua_block { | ||
| local healthcheck = require("resty.healthcheck") | ||
| -- shorten the cleanup window so it fires within the test | ||
| healthcheck._set_cleanup_interval(0.2) | ||
|
|
||
| local function new_checker(name) | ||
| return assert(healthcheck.new({ | ||
| name = name, | ||
| shm_name = "test_shm", | ||
| events_module = "resty.events", | ||
| checks = { | ||
| active = { | ||
| type = "tcp", | ||
| healthy = { interval = 0.1 }, | ||
| unhealthy = { interval = 0.1 }, | ||
| } | ||
| } | ||
| })) | ||
| end | ||
|
|
||
| -- two upstreams, each with health checks enabled | ||
| local checker1 = new_checker("upstream-1") | ||
| local checker2 = new_checker("upstream-2") | ||
|
|
||
| for i = 1, 3 do | ||
| assert(checker1:add_target("127.0.0.1", 20000 + i, nil, true)) | ||
| assert(checker2:add_target("127.0.0.1", 30000 + i, nil, true)) | ||
| end | ||
|
|
||
| -- mark every target on both checkers for immediate delayed removal | ||
| assert(checker1:delayed_clear(0)) | ||
| assert(checker2:delayed_clear(0)) | ||
|
|
||
| -- wait long enough for several cleanup windows to elapse | ||
| ngx.sleep(1.5) | ||
|
|
||
| local list1 = healthcheck.get_target_list("upstream-1", "test_shm") | ||
| local list2 = healthcheck.get_target_list("upstream-2", "test_shm") | ||
|
|
||
| -- Before the fix only the first checker in `hcs` is cleaned each | ||
| -- window, so checker2 keeps its purge-marked targets forever. | ||
| ngx.say("checker1 remaining: ", #list1) | ||
| ngx.say("checker2 remaining: ", #list2) | ||
| } | ||
| } | ||
| --- request | ||
| GET /t | ||
| --- response_body | ||
| checker1 remaining: 0 | ||
| checker2 remaining: 0 | ||
| --- timeout: 5 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.