Mercurial > prosody-modules
comparison mod_firewall/mod_firewall.lua @ 5381:32a9817c7516
mod_firewall: Initialize compiled chunk just once for all handlers
This should fix a case where some stateful dependencies (such as throttles)
produce separate instances for every call to new_handler(), leading to
surprising behaviour (e.g. rules executed via JUMP CHAIN vs ::deliver would
have separate rate limits).
This also adds better error handling in case the compiled code fails to run
for some reason.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 28 Apr 2023 13:27:06 +0100 |
parents | 8474a3b80200 |
children | fa8435a27f7e |
comparison
equal
deleted
inserted
replaced
5380:822d26271d9f | 5381:32a9817c7516 |
---|---|
556 return nil, "Error compiling (probably a compiler bug, please report): "..err; | 556 return nil, "Error compiling (probably a compiler bug, please report): "..err; |
557 end | 557 end |
558 local function fire_event(name, data) | 558 local function fire_event(name, data) |
559 return module:fire_event(name, data); | 559 return module:fire_event(name, data); |
560 end | 560 end |
561 local init_ok, initialized_chunk = pcall(chunk); | |
562 if not init_ok then | |
563 return nil, "Error initializing compiled rules: "..initialized_chunk; | |
564 end | |
561 return function (pass_return) | 565 return function (pass_return) |
562 return chunk()(active_definitions, fire_event, logger(filename), module, pass_return); -- Returns event handler with upvalues | 566 return initialized_chunk(active_definitions, fire_event, logger(filename), module, pass_return); -- Returns event handler with upvalues |
563 end | 567 end |
564 end | 568 end |
565 | 569 |
566 local function resolve_script_path(script_path) | 570 local function resolve_script_path(script_path) |
567 local relative_to = prosody.paths.config; | 571 local relative_to = prosody.paths.config; |