Skip to content

fix: load the native library once per JVM when NativeBase is reloaded - #17

Merged
msafonov merged 1 commit into
branch-1.1from
joom/1.1-fix-native-reload
Oct 11, 2026
Merged

msafonov merged 1 commit into
branch-1.1from
joom/1.1-fix-native-reload

Conversation

@msafonov

Copy link
Copy Markdown
Collaborator

Problem

CometNativeTaskKillSuite failed in every full test -pl spark run (2 of 4 tests: killed tasks never stopped), while passing when run alone.

CometSparkSessionExtensionsSuite ("Arrow properties") calls NativeBase.setLoaded(false) + NativeBase.load(). For the bundled library this unpacks libcomet to a new temp file and System.loads it again, so the JVM holds two copies with separate statics. Native methods linked before the reload stay bound to copy 1, methods first called after it bind to copy 2. Native.cancelPlan is first called only when a task is killed, so it looked up plans in copy 2's empty PLAN_CANCELLATIONS registry (found=false registry=0 with plans running) and the kill never reached native code.

Production is not affected: there the library is loaded once.

Change

NativeBase.load() remembers that the library is loaded in this JVM and, on a reload, only reapplies the logging init and Arrow properties.

Verification

  • Reproducing sequence CometAggregateSuite, CometSparkSessionExtensionsSuite, CometNativeTaskKillSuite in one JVM: before 2 failed, after 156 passed / 0 failed; Arrow properties passes.

🤖 Generated with Claude Code

NativeBase.load() after setLoaded(false), which CometSparkSessionExtensionsSuite
does to test the Arrow properties, unpacked libcomet to a new temporary file and
loaded it again. The JVM then held two copies of the library with separate
statics: native methods linked before the reload stayed bound to the first copy,
methods first called after it bound to the second. Native.cancelPlan, first
called only when a task is killed, looked up the plan in the second copy's empty
registry, so CometNativeTaskKillSuite failed whenever it ran after that suite in
the same JVM. load() now reapplies the logging and Arrow settings without loading
the library a second time.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the bug Something isn't working label Oct 11, 2026
@msafonov
msafonov merged commit 9eb6c4c into branch-1.1 Oct 11, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant