<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rspamd.git/src/lua/lua_dns.c, branch master</title>
<subtitle>rspamd</subtitle>
<id>http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/atom/src/lua/lua_dns.c?h=master</id>
<link rel='self' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/atom/src/lua/lua_dns.c?h=master'/>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/'/>
<updated>2026-06-16T19:05:53Z</updated>
<entry>
<title>[Fix] lua: refcount coroutine thread entries</title>
<updated>2026-06-16T19:05:53Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@rspamd.com</email>
</author>
<published>2026-06-16T19:05:26Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=35571dc8f860eb4c26461312f2ad932fedf5d9a8'/>
<id>urn:sha1:35571dc8f860eb4c26461312f2ad932fedf5d9a8</id>
<content type='text'>
The state/generation guards from the previous commit read the entry on
resume, so they only help while the entry is still allocated. If the
owning task is torn down while an async request is in flight, the entry
could be freed before the late completion fires, turning the guard into
a use-after-free.

Make thread_entry refcounted (ref.h, non-atomic - workers are single
threaded). The pool holds the initial reference; terminate_thread() and
the pool-full path now drop it via REF_RELEASE instead of freeing
directly, so the struct is destroyed only once the last reference goes
away. Every async library that stashes an entry for a later completion
now takes its own reference and drops it when done:

  - dns/util: retain at the request, release in the one-shot callback.
  - http/redis: retain at yield, release in the cbdata/ctx destructor
    (and, for redis, at each point that consumes ctx-&gt;thread).
  - tcp: retain at each yield, release at the matching resume, since the
    tcp cbdata has several direct-free error paths that bypass its
    destructor; pairing with yield/resume keeps the balance exact and
    leaves bad-argument paths (which return before yielding) untouched.

Combined with the generation guard, a completion that races task
teardown now finds the entry alive but DEAD/recycled and refuses the
resume, instead of dereferencing freed memory.
</content>
</entry>
<entry>
<title>[Fix] lua: state management for coroutine thread pool</title>
<updated>2026-06-16T15:35:55Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@rspamd.com</email>
</author>
<published>2026-06-16T15:35:34Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=d3a5a89f4f2160cfed285bea01a434df5f3aff71'/>
<id>urn:sha1:d3a5a89f4f2160cfed285bea01a434df5f3aff71</id>
<content type='text'>
Async libraries (dns/redis/tcp/http/util) capture the "currently
running" coroutine at a yield point and resume it later from a C
completion callback. Nothing previously guaranteed the entry resumed
was still the one captured: a double-fired event, a completion racing
task teardown, or an entry recycled into another task would resume the
wrong (or freed) coroutine and corrupt memory. These failures are
interleaving-dependent and invisible in isolation.

Give each pooled thread an explicit lifecycle (FREE/RUNNING/YIELDED/
DEAD) plus a generation counter, both carried in the existing
thread_entry and per-request cbdata structs - no new allocations on any
hot path:

  - get/return/terminate/yield/resume enforce legal state transitions,
    so returning a suspended thread or resuming a non-suspended one now
    aborts at the exact violation instead of corrupting a core later.
  - lua_thread_resume_checked() refuses to resume unless the thread is
    still YIELDED and its generation matches the value snapshotted at
    the yield point; a stale/duplicate completion becomes a logged
    no-op rather than a wrong-coroutine resume. All five async libs are
    migrated to it.
  - lua_tcp keeps cbd-&gt;thread pointing at the coroutine actually
    yielded by sync read/write, so the resume always targets it.

generation is bumped on every acquire and release, so an entry that
goes back to the pool and is handed out again no longer matches a
completion that was already in flight.
</content>
</entry>
<entry>
<title>[Rework] Further types conversion (no functional changes)</title>
<updated>2024-03-18T18:56:33Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@rspamd.com</email>
</author>
<published>2024-03-18T18:56:33Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=14c13854d3cae9d93c3d148be30fb72f1eaffe55'/>
<id>urn:sha1:14c13854d3cae9d93c3d148be30fb72f1eaffe55</id>
<content type='text'>
</content>
</entry>
<entry>
<title>[Rework] Use clang-format to unify formatting in all sources</title>
<updated>2023-07-26T09:49:23Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@rspamd.com</email>
</author>
<published>2023-07-26T09:49:23Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=537a7180a0d5132c11636c4fd8b1450cd99d352c'/>
<id>urn:sha1:537a7180a0d5132c11636c4fd8b1450cd99d352c</id>
<content type='text'>
No meaningful changes.
</content>
</entry>
<entry>
<title>[Rework] Use dynamic items for calling callbacks</title>
<updated>2022-05-09T20:25:23Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@rspamd.com</email>
</author>
<published>2022-05-09T20:25:23Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=22f603e83dd4fe3fc6d3e9e18b19bc87d57af235'/>
<id>urn:sha1:22f603e83dd4fe3fc6d3e9e18b19bc87d57af235</id>
<content type='text'>
It is trivial to get a static item by dynamic item by just subtracting
pointers. So there is no need in other complications.
</content>
</entry>
<entry>
<title>[Minor] Adopt Rspamd to flags in rdns reply</title>
<updated>2021-12-01T19:10:29Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@highsecure.ru</email>
</author>
<published>2021-12-01T19:10:29Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=e0f1732a975260140c235223d126e3e8a849f1e7'/>
<id>urn:sha1:e0f1732a975260140c235223d126e3e8a849f1e7</id>
<content type='text'>
</content>
</entry>
<entry>
<title>[Minor] Add flags for rspamd_lua_parse_table_arguments</title>
<updated>2019-07-01T10:08:43Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@highsecure.ru</email>
</author>
<published>2019-07-01T10:08:43Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=6bd388ae930900bef74532f810c4411650761868'/>
<id>urn:sha1:6bd388ae930900bef74532f810c4411650761868</id>
<content type='text'>
</content>
</entry>
<entry>
<title>[Minor] Refactor DNS resolver invocations</title>
<updated>2019-04-11T14:00:01Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@highsecure.ru</email>
</author>
<published>2019-04-11T14:00:01Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=6943c3c3a4dd1334aa041fcd7df9598ecec3f152'/>
<id>urn:sha1:6943c3c3a4dd1334aa041fcd7df9598ecec3f152</id>
<content type='text'>
</content>
</entry>
<entry>
<title>[Minor] Fix misguiding indentation</title>
<updated>2018-12-15T21:12:07Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@highsecure.ru</email>
</author>
<published>2018-12-15T21:12:07Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=2cf0beb5d0da35aceed32543e7602e606888dcfa'/>
<id>urn:sha1:2cf0beb5d0da35aceed32543e7602e606888dcfa</id>
<content type='text'>
</content>
</entry>
<entry>
<title>[Project] Another rework for symbols cache</title>
<updated>2018-10-29T12:22:46Z</updated>
<author>
<name>Vsevolod Stakhov</name>
<email>vsevolod@highsecure.ru</email>
</author>
<published>2018-10-29T12:22:46Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/rspamd.git/commit/?id=4929e73f2baaa0dd29759a6705ac8dd1b06beb90'/>
<id>urn:sha1:4929e73f2baaa0dd29759a6705ac8dd1b06beb90</id>
<content type='text'>
</content>
</entry>
</feed>
