Skip to content

fix(bigquery-jdbc): abort session when connection is closed - #14273

Open
Neenu1995 wants to merge 6 commits into
mainfrom
fix-session-abort
Open

fix(bigquery-jdbc): abort session when connection is closed#14273
Neenu1995 wants to merge 6 commits into
mainfrom
fix-session-abort

Conversation

@Neenu1995

@Neenu1995 Neenu1995 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #13922

@Neenu1995
Neenu1995 requested review from a team as code owners September 4, 2026 18:56

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces changes to automatically abort active BigQuery sessions when a connection is closed. Specifically, it adds an abortSession method in BigQueryConnection that executes CALL BQ.ABORT_SESSION(); and cleans up session-related connection properties. Corresponding unit and integration tests have been added to verify this behavior. The feedback suggests a minor improvement to the exception message when handling InterruptedException to more accurately reflect that the interruption occurred during session abortion.

QueryJobConfiguration.newBuilder("CALL BQ.ABORT_SESSION();")
.setConnectionProperties(this.queryProperties)
.build();
Job abortJob = this.bigQuery.create(JobInfo.of(abortSessionJobConfig));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use query API instead? It'd allow us to save 1 roundtrip to the backend

QueryJobConfiguration.Builder transactionBeginJobConfig =
QueryJobConfiguration.newBuilder("BEGIN TRANSACTION;");
try {
if (this.sessionInfoConnectionProperty != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if looks weird to me. We check sessionInfoConnectionProperty, but we call setConnectionproperties(this.queryProperties). queryProperties have more data.
Should we always do setConnectionProperties & do seCreateSession(true) only when sessionInfo is null?

Job job = this.bigQuery.create(JobInfo.of(transactionBeginJobConfig.build()));
job = job.waitFor();
Job transactionBeginJob = this.bigQuery.getJob(job.getJobId());
if (this.sessionInfoConnectionProperty == null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't call updateSessionInfo due to any of 3 != null checks, this is an error, we can't mark transactionStarted = true. We need to either throw custom error or just remove these checks.

}
}

synchronized void updateSessionInfo(String sessionId) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Session is immutable during connection lifetime, right? This method should reflect that imo

boolean transactionStarted;
volatile ConnectionProperty sessionInfoConnectionProperty;
// isSessionCreatedByDriver is false by default.
boolean isSessionCreatedByDriver = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this PR will abort the session on connection close when it is created by our driver.

And we are not creating a new conn prop (e.g. keepSessionAlive default false) that would let users NOT abort the sessions created by the driver when connection is closed?

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.

bigquery-jdbc: unable to run SQL 'CALL BQ.ABORT_SESSION()'

3 participants