hive icon indicating copy to clipboard operation
hive copied to clipboard

HIVE-29302: Wider Tez session open scope should be guarded to prevent local resource leaks

Open abstractdog opened this issue 3 months ago • 5 comments

What changes were proposed in this pull request?

Encapsulate a wider code path in error-handling while opening a Tez session. The point of the patch is nothing more than refactoring code to a separate method:

    try {
      openInternalUnsafe(isAsync, console);
    } catch (Exception e) {
      LOG.info("Failed to open session, deleting scratch dir to prevent resource leak...", e);
      cleanupScratchDir();
      throw e;
    }

Why are the changes needed?

A scratch directory can leak if an exception is thrown after it’s created and resources have been placed into it.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Unit test added.

abstractdog avatar Nov 03 '25 15:11 abstractdog

Quality Gate Passed Quality Gate passed

Issues 2 New issues 0 Accepted issues

Measures 0 Security Hotspots 0.0% Coverage on New Code 0.0% Duplication on New Code

See analysis details on SonarQube Cloud

not about to handle this:

[Either log this exception and handle it, or rethrow it with some contextual information.](https://sonarcloud.io/project/issues?pullRequest=6161&open=AZpLt4QCPQuC7unSj798&id=apache_hive)

no more useful contextual information can be added here than "hey, I caught this exception, cleaned up, and now re-throwing the session open failure exception"

abstractdog avatar Nov 04 '25 12:11 abstractdog

Changes makes sense to me, to cleanup scratch directory in case of exception before startSessionAndContainers() in openInternal() method

LGTM +1 (non-binding)

Aggarwal-Raghav avatar Nov 10 '25 17:11 Aggarwal-Raghav

thanks @deniskuzZ , @Aggarwal-Raghav for the reviews! restarted test to have a green precommit, then I'll merge

abstractdog avatar Dec 10 '25 16:12 abstractdog