Fix concurrency, exception-safety, and correctness bugs in JNI layer …#326
Merged
bernardladenthin merged 1 commit intoJul 11, 2026
Merged
Conversation
…and Java API JNI / native fixes: - Guard rerank / embedding / streaming to_json() calls against uncaught C++ exceptions crossing the JNI boundary, which would otherwise abort the JVM. - Hold a jllama_context user reference for the attached NativeServer worker so closing the model cannot free the context out from under the running HTTP frontend (use-after-free). - Fix close()-during-inference hang: add a closing flag that unblocks readers parked in next()/wait_for_all(), and decrement the user count under the context mutex so the teardown wait cannot free the mutex/condvar before the releaser notifies (latent use-after-free in the ref-count itself). - Fix NativeServer jstring_to_utf8 calling getBytes with a Charset argument while resolving the String overload (deterministic break on every server start); cache the JNI IDs thread-safely. - Initialize parse_string_array slots to nullptr so an OOM path cannot free uninitialized memory. - Add a pending-exception check in parse_jstring. Java fixes: - Widen token counts to long in the protocol translators and ChatResponseParser.extractUsageField to avoid truncation above ~2.1B tokens. - Honor a pre-cancelled CancellationToken in complete() (stop resetting it at entry); fix completeAsJson javadoc (the params object is not mutated). Tests and docs: - Extract the OuteTTS codec filter into a testable helper; add rerank bounds and codec-filter unit tests, and a model-gated close()-during-inference test. - Remove the dead BUILD_SHARED_LIBS ON line in CMakeLists.txt. - Update plan and TODO docs to reflect the real teardown design.
68989f6 to
88fdd6d
Compare
6f09d88
into
bernardladenthin:main
66 of 73 checks passed
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.
…and Java API
JNI / native fixes:
Java fixes:
Tests and docs:
Summary
Test plan
Related issues / PRs
Checklist
CONTRIBUTING.mdandCODE_OF_CONDUCT.mdSECURITY.md)