Skip to content

Commit 9a0f70f

Browse files
committed
cancel if failed
1 parent 67fa7ea commit 9a0f70f

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryStatement.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ ResultSet processArrowResultSet(TableResult results, Job job) throws SQLExceptio
810810
JobId currentJobId = results.getJobId();
811811
TableId destinationTable = getDestinationTable(currentJobId);
812812
Schema schema = results.getSchema();
813+
Future<?> populateBufferWorker = null;
813814
try {
814815
String parent = String.format("projects/%s", destinationTable.getProject());
815816
String srcTable =
@@ -833,7 +834,7 @@ ResultSet processArrowResultSet(TableResult results, Job job) throws SQLExceptio
833834
ReadSession readSession = getReadSession(builder.build());
834835
this.arrowBatchWrapperBlockingQueue = new LinkedBlockingDeque<>(getBufferSize());
835836
// deserialize and populate the buffer async, so that the client isn't blocked
836-
Future<?> populateBufferWorker =
837+
populateBufferWorker =
837838
populateArrowBufferedQueue(
838839
readSession, this.arrowBatchWrapperBlockingQueue, getBigQueryReadClient());
839840

@@ -855,6 +856,9 @@ ResultSet processArrowResultSet(TableResult results, Job job) throws SQLExceptio
855856
return arrowResultSet;
856857

857858
} catch (Exception | OutOfMemoryError ex) {
859+
if (populateBufferWorker != null) {
860+
populateBufferWorker.cancel(true);
861+
}
858862
if (ex instanceof OutOfMemoryError || ex instanceof RejectedExecutionException) {
859863
throw new BigQueryJdbcException(
860864
"Failed to execute query: Unable to allocate background threads to process the query results. Connection-scoped thread pool limit of 100 threads was reached or system is out of memory.",
@@ -1078,6 +1082,11 @@ BigQueryJsonResultSet processJsonResultSet(TableResult results, Job job) throws
10781082
schema, this.bigQueryFieldValueListWrapperBlockingQueue, rpcResponseQueue);
10791083
taskList.add(populateBufferWorker);
10801084
} catch (RejectedExecutionException | OutOfMemoryError e) {
1085+
for (Future<?> task : taskList) {
1086+
if (task != null) {
1087+
task.cancel(true);
1088+
}
1089+
}
10811090
throw new BigQueryJdbcException(
10821091
"Failed to execute query: Unable to allocate background threads to process the query results. Connection-scoped thread pool limit of 100 threads was reached or system is out of memory.",
10831092
e);

0 commit comments

Comments
 (0)