fix: lazily initialize tokenizer HTTP client#1117
Open
arnabnandy7 wants to merge 1 commit into
Open
Conversation
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
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.
Summary
Fixes #978.
Prevents
LocalTokenizerLoaderfrom eagerly creating an OkHttp client during class initialization. This allows GraalVM native-image builds, including Quarkus native builds, to analyze the class without attempting to capture build-time SSL and socket state.Problem
LocalTokenizerLoaderpreviously initialized its HTTP client as a static field:During native-image generation, GraalVM could initialize
LocalTokenizerLoaderat build time and encounter theOkHttpClientobject graph, including its SSL socket factory. Because this operating-system-dependent state cannot safely be stored in the native image heap, the build failed with an error tracing the object through:Requiring consumers to configure
LocalTokenizerLoaderfor runtime initialization is a workaround, but places framework-specific configuration on SDK users.Changes
OkHttpClientconstruction with the initialization-on-demand holder pattern.Implementation details
The default client is stored in a nested holder class:
The JVM initializes this nested class only when
HttpClientHolder.INSTANCEis first accessed. This provides lazy and thread-safe initialization without explicit synchronization.Calls that do not require network access, such as resolving the tokenizer name or loading an already cached model, therefore do not construct the HTTP client.
Compatibility
This change does not affect the public API or normal tokenizer behavior.
Applications should no longer need the following Quarkus workaround for
LocalTokenizerLoader:The separate interactions-client linkage error originally reported against version
1.51.0does not apply to current releases because the experimental interactions implementation was removed in the1.54.0release line.Validation
git diff --checkpassed.LocalTokenizerLoader.<clinit>no longer constructs anOkHttpClient; construction is isolated toHttpClientHolder.<clinit>.Full repository test/package execution remains affected by unrelated baseline issues involving generated type compilation and existing Animal Sniffer failures.