Skip to content

Commit 5a6318a

Browse files
committed
Fix issue where connection was closed during retry.
- Resolved an issue where SnowflakeOutputConnection was prematurely closed during retries in the COPY operation. - Refactored the code to use try-with-resources for managing SnowflakeOutputConnection, ensuring a new connection is created for each retry. - Removed the explicit con.close() call in the finally block, as connections are now safely managed within the retry loop.
1 parent 76dc706 commit 5a6318a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/main/java/org/embulk/output/snowflake/SnowflakeCopyBatchInsert.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,10 @@ public Void call() throws SQLException, InterruptedException, ExecutionException
425425
try {
426426
uploadFuture.get();
427427

428-
SnowflakeOutputConnection con = (SnowflakeOutputConnection) connector.connect(true);
429428
int retries = 0;
430429
while (true) {
431-
try {
430+
try (SnowflakeOutputConnection con =
431+
(SnowflakeOutputConnection) connector.connect(true)) {
432432
logger.info("Running COPY from file {}", snowflakeStageFileName);
433433

434434
long startTime = System.currentTimeMillis();
@@ -461,8 +461,6 @@ public Void call() throws SQLException, InterruptedException, ExecutionException
461461
String.format(
462462
"Copy error %s file %s retries: %d", e, snowflakeStageFileName, retries));
463463
Thread.sleep(retries * retries * 1000);
464-
} finally {
465-
con.close();
466464
}
467465
}
468466
} finally {

0 commit comments

Comments
 (0)