Skip to content

Fix native TensorFlow resource leaks causing non-deterministic SIGABRT in tests (#778) - #903

Open
harshitsingh070 wants to merge 1 commit into
apache:mainfrom
harshitsingh070:fix/tensorflow-test-778
Open

harshitsingh070 wants to merge 1 commit into
apache:mainfrom
harshitsingh070:fix/tensorflow-test-778

Conversation

@harshitsingh070

Copy link
Copy Markdown
Contributor

Problem

TensorflowModelTest failed intermittently with Process Exit Code: 134 (SIGABRT) and
"The forked VM terminated without properly saying goodbye" during JVM shutdown.
The previous fix (#781) only cleaned up resources inside the test itself and did not
address the actual leaks.

Root cause

TensorFlow Java native tensors are released by JavaCPP deallocators when not closed
explicitly. Leaked tensors were therefore freed by the GC at arbitrary times, including
during JVM shutdown, racing with Session/Graph teardown and aborting the process.

The real leaks were:

  • TensorflowModel.train() created TBool.scalarOf(true) on every batch and never closed it.
  • TensorflowModel.predict() never closed the Result returned by session.runner().run().
  • TensorflowOperatorTest leaked a Result and feed tensors in almost every test.

Because Surefire runs all test classes in one forked JVM, these leaks accumulated and the
crash was often attributed to whichever test class ran last (TensorflowModelTest).

Fix

  • Close the training-mode tensor per batch in train() via try-with-resources.
  • Track and close the Result from predict() in TensorflowModel.close().
  • Close every Result, feed tensor, and TBool/TFloat32 in TensorflowOperatorTest
    with try-with-resources.

All native resources are now released deterministically before the session/graph are
closed, so no deferred cleanup is left at JVM shutdown.

Testing

  • mvn -pl wayang-platforms/wayang-tensorflow test passes repeatedly (13 tests, multiple runs).
  • Could not reproduce the intermittent crash on Windows, but the leak-driven shutdown race
    is removed.

Fixes #778

Close the per-batch training tensor in train(), the prediction Result in predict()/close(), and all Results and feed tensors in TensorflowOperatorTest. Previously these leaked and were freed by the GC during JVM shutdown, racing with Session/Graph teardown and aborting the process (exit 134).

Fixes apache#778
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.

Non-deterministic tensorflow test failing

1 participant