aboutsummaryrefslogtreecommitdiff
path: root/src/lua/lua_upstream.c
AgeCommit message (Collapse)AuthorLines
2026-05-02[Minor] lua_upstream: pack acquired/retired into bitfieldsVsevolod Stakhov-6/+6
Two gboolean (gint) fields cost 8 padded bytes plus alignment per wrapper. Each wrapper only needs two bits, so use unsigned:1 bitfields instead. struct rspamd_lua_upstream shrinks from 24 to 16 bytes on 64-bit targets. No behaviour change.
2026-05-02[Fix] lua_upstream: retire inflight on __gc when caller forgets ok/failVsevolod Stakhov-5/+23
Lua plugin code can drop a get_upstream_*() wrapper without ever calling :ok or :fail (e.g. when an async callback never fires or is written incorrectly). Without retirement, the C-side inflight counter introduced for P2C scoring leaks indefinitely and biases selection away from the affected upstream. Add acquired/retired bookkeeping on the Lua wrapper: - lua_push_upstream() takes an explicit acquired flag. The three get_upstream_* bindings pass TRUE; all_upstreams() inserter passes FALSE since it returns a view, not a fresh inflight reference. - The watcher path inlines lua_newuserdata; explicitly zero the new fields there so uninitialised stack memory doesn't trigger spurious retire calls. - :ok and :fail set retired = TRUE so the destructor doesn't double retire when the caller did pair properly. - The __gc destructor calls rspamd_upstream_release when acquired && !retired, decrementing inflight without affecting error counts or latency. Lua GC is non-deterministic, so retirement may lag for some time; that's acceptable noise for a load comparator and strictly better than an unbounded leak. Tests in test/lua/unit/upstream.lua cover smoke-level API usage, the abandoned-wrapper path, view safety from all_upstreams(), and double-retirement protection.
2026-04-25[Fix] upstream: make addr accessors and all_upstreams pending-safeVsevolod Stakhov-1/+8
The PENDING_RESOLVE upstream state introduced earlier kept pending entries out of the alive list, but `:all_upstreams()` walks the full `ups` array and exposes them to Lua callers - which then crashed in `s:get_addr()` because `rspamd_upstream_addr_next/cur/port` indexed a NULL `addrs.addr`. Defensive fix at the C accessor layer: * rspamd_upstream_addr_next / _cur now return NULL when the upstream has no addresses (NULL or empty array). This is the safe layer that every other consumer eventually goes through. * rspamd_upstream_port returns the parsed `deferred_port` for pending upstreams (so callers that just want a port get a sensible answer) and -1 if even that is unknown. * lua_upstream:get_addr() pushes nil when the C side has no address. Audit of `:all_upstreams()` callers, all updated to skip pending: * lua_redis prepare_redis_call (SCRIPT LOAD broadcast): if `s:get_addr()` is nil, mark the slot as "tempfail" so the next retry will pick it up once DNS comes back, log, and skip it. * rspamadm statistics_dump connect_to_upstream: log and return early before opening a redis connection with a nil host. * clickhouse plugin check_clickhouse_upstream: skip with an info log so the periodic check tries again next tick. The DKIM Vault helper already passes `upstream = ... or nil` to http.request and lets the HTTP layer fall back to URL-based connect, which remains the right behaviour.
2024-03-18[Rework] Further types conversion (no functional changes)Vsevolod Stakhov-31/+31
2024-03-05[Project] Convert the remainingVsevolod Stakhov-8/+8
2023-07-26[Rework] Use clang-format to unify formatting in all sourcesVsevolod Stakhov-184/+180
No meaningful changes.
2022-07-02[Feature] Allow lua_http module to accept upstreamsVsevolod Stakhov-14/+9
2021-11-07[Minor] Allow to get a port for a specific upstreamVsevolod Stakhov-0/+23
2021-10-11[Minor] Lua_upstream: Add get_name methodVsevolod Stakhov-0/+23
2020-08-17[Fix] Store reference of upstream list in upstreams objectsVsevolod Stakhov-31/+80
2019-11-13[Minor] Add failure reason in the upstreams codeVsevolod Stakhov-1/+9
2019-09-16[Rework] Lua core: Use lightuserdata to index classesVsevolod Stakhov-24/+4
2019-05-24[Fix] Do not use lightuserdata for tracebackVsevolod Stakhov-3/+1
LuaJIT limits lightuserdata usage to 47 bits. On Arm64, this leads to break of the C <-> Lua interoperability using this type. This rework has changed traceback function behaviour from lightuserdata opaque pointer (GString * in particular) to luaL_Buffer. Issue: #2906
2019-02-18[Fix] Core: Fix address rotation bugVsevolod Stakhov-1/+1
Previously, upstream.get_addr function returned the new address of the upstream. Unfortunately, it was used for printing addresses. It caused the following situation: let's imagine we have A1 and A2 where A1 was initially selected. So the connection was performed to A1: Current addr Selected addr Connect+---------+ A2+------>A1 A1 | +-+Print failure<---+ A1+------>A2 A2 | +----+ +->Mark failure+-------->+ A2 | +----+ But the failure OP as well as log message told about `A2` where the real problem happened with `A1`. This commit adds distinguishing between getting the next and the current address of the upstream resolving this issue.
2018-12-05[Feature] Allow to add upstream watchers to Lua APIVsevolod Stakhov-4/+167
2018-08-09[Feature] Add support for Lua API tracingVsevolod Stakhov-0/+9
2018-07-02[Feature] Distinguish IP failures from connection failuresVsevolod Stakhov-1/+7
2018-03-12[Minor] Fix table argument parsingVsevolod Stakhov-3/+5
2018-03-12[Minor] Fix upstreams parsingVsevolod Stakhov-6/+23
2018-02-15[Minor] Allow to create upstream lists without rspamd_configVsevolod Stakhov-6/+16
2017-12-16[Minor] Allow to get all upstreams from the list in LuaVsevolod Stakhov-0/+35
2017-03-23[Minor] Fix various style issuesVsevolod Stakhov-2/+0
2016-05-05[Feature] Use rspamd specific type checks for userdataVsevolod Stakhov-2/+2
2016-02-09Fix some issues found by coverityVsevolod Stakhov-1/+4
2016-02-04Switch the rest to apache 2Vsevolod Stakhov-20/+12
2015-11-21Use new rotation logic in the codeVsevolod Stakhov-2/+4
2015-11-20Fix upstreams usageVsevolod Stakhov-31/+16
2015-06-23Avoid non-portable lua integers.Vsevolod Stakhov-1/+1
2015-04-09Forgot @module.Vsevolod Stakhov-0/+1
2015-04-09Document lua upstream.Vsevolod Stakhov-30/+58
2014-10-28Fix lua upstream code.Vsevolod Stakhov-274/+45
2014-08-25Use rspamd_ prefix.Vsevolod Stakhov-2/+2
2014-08-25Use modules preload for lua.Vsevolod Stakhov-5/+20
2014-08-17Rework lua function names to avoid ambiguity.Vsevolod Stakhov-7/+7
2014-07-23Unify style without sorting headers.Vsevolod Stakhov-57/+78
2014-07-23Revert "Unify code style."Vsevolod Stakhov-79/+58
This reverts commit e0483657ff6cf1adc828ccce457814d61fe90a0d.
2014-07-23Unify code style.Vsevolod Stakhov-58/+79
2014-04-30Refactor config API.Vsevolod Stakhov-2/+2
2013-06-08Adopt to lua 5.2.Vsevolod Stakhov-4/+4
2013-06-06Avoid arrays addresses manipulation.Vsevolod Stakhov-3/+20
2013-06-01Rework socket creation logic to support both ipv4 and ipv6 sockets.Vsevolod Stakhov-5/+5
2012-07-26* Add lua worker type and lua worker bindings.Vsevolod Stakhov-0/+4
* Add lua utility library for basic utils. * Fixes lua_buffer code. Fix lua loading error. Added some other lua utility functions.
2012-04-06* Add ratelimit pluginVsevolod Stakhov-1/+1
Some polishing of lua task api.
2012-03-26* Add lua bindings for upstream API.Vsevolod Stakhov-0/+521