Skip to content

Thread-safety / free-threaded fixes with tests#120

Open
greateggsgreg wants to merge 18 commits intopy4n6:mainfrom
greateggsgreg:freethreading-compat-fixes
Open

Thread-safety / free-threaded fixes with tests#120
greateggsgreg wants to merge 18 commits intopy4n6:mainfrom
greateggsgreg:freethreading-compat-fixes

Conversation

@greateggsgreg
Copy link
Copy Markdown
Contributor

@greateggsgreg greateggsgreg commented Apr 30, 2026

Recent commits declared the module free-thread-compatible (Py_MOD_GIL_NOT_USED, PR #119) and rewrote pytsk3's own error storage to be thread-local (PR #118). This PR addresses other thread safety and security issues surfaced during testing.

I introduced fine-grained locking (per-instance, not module-wide), so on free-threaded Python pytsk3 calls genuinely run in parallel. Stress workload: 32 threads x 2000 iters x 6 reads = 384,000 ops on a shared File:

Build Time Speedup
Python 3.14 GIL 1.55 s baseline
Python 3.11 GIL 1.57 s ~same as 3.14 GIL
Python 3.14t free-threaded 0.18 s ~9×

Tests include:

  • Concurrent ops: independent and shared Img_Info/FS_Info/File/Volume_Info reads, opens, and iterations.
  • Parent keepalive: every child path (Directory.iternext, File.iternext, FS_Info.open*, File.as_directory, Volume_Info.iternext, borrowed-struct getters) survives parent drop + GC.
  • Close-vs-read race: Img_Info.close from one thread while readers are mid-flight produces a clean IOError, never a crash.
  • Iterator cursor: 4 threads sharing one Directory iterator consume exactly baseline entries — no duplicates, no skips.
  • Recursive walk stress + GC under load: 8 threads × 20 iters × full tree walk with concurrent gc.collect() produces identical entry counts.
  • Subinterpreter import: validates tsk_init's std::call_once across interpreters
  • Security: Tests for regressions of security-relevant issues that include an out-of-bounds read and NULL deref issues

Finally - I added Python 3.14 free-threaded build targets for all platforms which also have tests run against them.

#121

@greateggsgreg
Copy link
Copy Markdown
Contributor Author

Looks like ubuntu repos are having connectivity issues. Run a rebuild on the same code and it should be fine.

@joachimmetz
Copy link
Copy Markdown
Member

per https://status.canonical.com/

Canonical and Ubuntu Status
Canonical’s web infrastructure is under a sustained, cross-border attack and we are working to address it. We will provide more information in our official channels as soon as we are able to. 

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.

2 participants