Skip to content

Commit 56e09ec

Browse files
fix: allow timer to restart by APISIX (#112)
1 parent 63debcb commit 56e09ec

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/skywalking/client.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ local initialized = false
3131
-- After report instance properties successfully, it sends keep alive packages.
3232
function Client:startBackendTimer(backend_http_uri)
3333
initialized = true
34+
self.stopped = false
3435
local metadata_buffer = ngx.shared.tracing_buffer
3536

3637
-- The codes of timer setup is following the OpenResty timer doc
@@ -42,6 +43,7 @@ function Client:startBackendTimer(backend_http_uri)
4243

4344
check = function(premature)
4445
if not premature and not self.stopped then
46+
log(ngx.INFO, "running timer")
4547
local instancePropertiesSubmitted = metadata_buffer:get('instancePropertiesSubmitted')
4648
if (instancePropertiesSubmitted == nil or instancePropertiesSubmitted == false) then
4749
self:reportServiceInstance(metadata_buffer, backend_http_uri)

t/client.t

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,37 @@ true
114114
--- no_error_log
115115
language: lua
116116
Go keepAlive
117+
118+
119+
120+
=== TEST 3: start backend timer then destory then restart backend timer
121+
--- config
122+
location /t {
123+
content_by_lua_block {
124+
local client = require("skywalking.client")
125+
client.backendTimerDelay = 0.1
126+
client:startBackendTimer("http://127.0.0.1:" .. ngx.var.server_port)
127+
ngx.sleep(0.1)
128+
ngx.say('ok')
129+
130+
local ok, err = client:destroyBackendTimer()
131+
if not err then
132+
ngx.say(ok)
133+
else
134+
ngx.say(err)
135+
end
136+
137+
client:startBackendTimer("http://127.0.0.1:" .. ngx.var.server_port)
138+
ngx.sleep(0.1)
139+
ngx.say('ok')
140+
}
141+
}
142+
--- response_body
143+
ok
144+
true
145+
ok
146+
--- grep_error_log: running timer
147+
--- grep_error_log_out
148+
running timer
149+
running timer
150+
running timer

0 commit comments

Comments
 (0)