pooled hugot embedder close race - #19
Open
dovinmu wants to merge 8 commits into
Open
Conversation
Two critical bugs were fixed: Bug 1: Close() during Embed() caused SIGSEGV - Close() could destroy the ONNX session while Embed() was still using it - Fix: Use WaitGroup to track in-flight operations, Close() waits for them Bug 2: Multiple Close() calls caused panic - Calling Close() multiple times would call session.Destroy() multiple times - Fix: Use sync.Once to ensure Close() only executes once Changes: - Added synchronization fields to PooledHugotEmbedder: - closed (atomic.Bool): prevents new Embed() after Close() - wg (sync.WaitGroup): tracks in-flight Embed() calls - closeOnce (sync.Once): ensures Close() runs exactly once - closeErr (error): stores error from Close() - Updated Embed() to check closed flag and register with WaitGroup - Updated Close() to use sync.Once and wait for in-flight operations Tests added: - close_race_test.go: Tests for both bug scenarios - happy_path_test.go: 7 tests for normal usage patterns - pipeline_collision_test.go: Tests for pipeline selection Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Two critical bugs were fixed: Bug 1: Close() during Embed() caused SIGSEGV - Close() could destroy the ONNX session while Embed() was still using it - Fix: Use WaitGroup to track in-flight operations, Close() waits for them Bug 2: Multiple Close() calls caused panic - Calling Close() multiple times would call session.Destroy() multiple times - Fix: Use sync.Once to ensure Close() only executes once Changes: - Added synchronization fields to PooledHugotEmbedder: - closed (atomic.Bool): prevents new Embed() after Close() - wg (sync.WaitGroup): tracks in-flight Embed() calls - closeOnce (sync.Once): ensures Close() runs exactly once - closeErr (error): stores error from Close() - Updated Embed() to check closed flag and register with WaitGroup - Updated Close() to use sync.Once and wait for in-flight operations Tests added: - close_race_test.go: Tests for both bug scenarios - happy_path_test.go: 7 tests for normal usage patterns - pipeline_collision_test.go: Tests for pipeline selection
….com/dovinmu/termite into fix/pooled-hugot-embedder-close-race
ajroetker
reviewed
Jan 15, 2026
timkaye11
approved these changes
Jan 16, 2026
ajroetker
reviewed
Jan 16, 2026
| if err != nil { | ||
| t.Fatalf("Failed to create embedder: %v", err) | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
I think maybe a good prompt of having it consolidate batch_test.go close_race_test.go and pipeline_collision_test.go into a minimal subset that will be used to ensure no regressions might be good here.
ajroetker
reviewed
Jan 16, 2026
ajroetker
left a comment
Contributor
There was a problem hiding this comment.
Good find btw! If you're down, maybe you could check for this in the other model types?
Contributor
Author
|
@ajroetker looks like the other models had exactly the same possible race condition. Tested, built & served embeddings locally |
1 task
Contributor
|
Dope stuff and good find! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@timkaye11 @ajroetker I've been testing out a new way of doing tool-assisted bug hunting on the termite repo and found this. Hoping it might help with my experience of using termite on Arch--every once in a while it'll get stuck and I have to restart it to get it serving embeddings again. Very curious if you can find any flaws with this finding! As I said it's still experimental and I'm building confidence in the approach
Two critical bugs were found in
PooledHugotEmbedderand confirmed with real-world testing.Test Matrix
Quick Summary
Close()duringEmbed()Close()callsSetup (Required for all ONNX tests)
From the
termitedirectory:Pattern Demos (No Dependencies)
These demonstrate the bug patterns without requiring ONNX Runtime:
Bug Reproducers (Requires ONNX)
These tests are in
pkg/termite/lib/embeddings/close_race_test.go.Pre-fix: These tests will CRASH (SIGSEGV or panic).
Post-fix: These tests will PASS.
From the
termitedirectory (after setup above):Happy Path Tests (Requires ONNX)
These tests verify normal usage works. They should PASS before and after the fix.
E2E Bash Script
Tested:
Unit Tests
From the
termitedirectory (after setup above):The Fixes
Both bugs are fixed by adding synchronization to
PooledHugotEmbedder:Comparing Before/After the Fix
The fix is on branch
fix/pooled-hugot-embedder-close-racein the termite repo.