Skip to content

Make c-validator module thread-safe - #10

Merged
locker merged 4 commits into
masterfrom
app-threads-fix
Sep 8, 2026
Merged

Make c-validator module thread-safe#10
locker merged 4 commits into
masterfrom
app-threads-fix

Conversation

@locker

@locker locker commented Sep 8, 2026

Copy link
Copy Markdown
Member

This PR makes the c-validator module safe to use in Tarantool application threads.

Closes #9

Reasons to drop it:
 - Tarantool panics on any malloc failure so there's no need to
   gracefully handle OOM here.
 - We don't test the code handling OOM (there's no easy way to test it).
 - We store a reference to the OOM error in a global variable, which
   means we must make it thread-local to fix #9. If we dropped the OOM
   handling code altogether, we wouldn't need to bother.

Needed for #9
cv__init is called once when the module is loaded so there's no need to
release previously taken Lua references. Moreover, releasing the old
references makes it difficult to reproduce #9: the problem is that
luaL_ref called right after luaL_unref takes the same slot in the
reference table so with the current initialization procedure the bug may
only occur if application threads race to load the c-validator module in
parallel.

Needed for #9
This commit marks all global variables used in the c-validator module
thread-local. This should be enough to make it usable in Tarantool
application threads.

Closes #9
@locker
locker requested a review from unera September 8, 2026 11:15
@locker
locker merged commit 38458a3 into master Sep 8, 2026
1 check passed
@locker
locker deleted the app-threads-fix branch September 8, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

c-validator is unsafe to use in Tarantool application threads

2 participants