Software /
code /
prosody
Annotate
util/watchdog.lua @ 12894:0598d822614f 0.12 0.12.3
mod_websocket: Fire pre-session-close event (fixes #1800)
This event was added in a7c183bb4e64 and is required to make mod_smacks know
that a session was intentionally closed and shouldn't be hibernated (see
fcea4d9e7502).
Because this was missing from mod_websocket's session.close(), mod_smacks
would always attempt to hibernate websocket sessions even if they closed
cleanly.
That mod_websocket has its own copy of session.close() is something to fix
another day (probably not in the stable branch). So for now this commit makes
the minimal change to get things working again.
Thanks to Damian and the Jitsi team for reporting.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 20 Feb 2023 18:10:15 +0000 |
parent | 8555:4f0f5b49bb03 |
child | 12545:5059a639f61e |
rev | line source |
---|---|
4401
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local timer = require "util.timer"; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local setmetatable = setmetatable; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local os_time = os.time; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
5 local _ENV = nil; |
8555
4f0f5b49bb03
vairious: Add annotation when an empty environment is set [luacheck]
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
6 -- luacheck: std none |
4401
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local watchdog_methods = {}; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local watchdog_mt = { __index = watchdog_methods }; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
11 local function new(timeout, callback) |
4401
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local watchdog = setmetatable({ timeout = timeout, last_reset = os_time(), callback = callback }, watchdog_mt); |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 timer.add_task(timeout+1, function (current_time) |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local last_reset = watchdog.last_reset; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 if not last_reset then |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 return; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local time_left = (last_reset + timeout) - current_time; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 if time_left < 0 then |
4891
189cfe565d03
util.watchdog: Pass watchdog object to callback so that it doesn't always have to be a closure
Matthew Wild <mwild1@gmail.com>
parents:
4401
diff
changeset
|
20 return watchdog:callback(); |
4401
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 return time_left + 1; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 end); |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 return watchdog; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 function watchdog_methods:reset() |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 self.last_reset = os_time(); |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 function watchdog_methods:cancel() |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 self.last_reset = nil; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
35 return { |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
36 new = new; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
37 }; |