Abacn commented on code in PR #23757:
URL: https://github.com/apache/beam/pull/23757#discussion_r1008161538


##########
sdks/java/io/common/src/test/java/org/apache/beam/sdk/io/common/DatabaseTestHelper.java:
##########
@@ -100,13 +100,21 @@ public static void createTable(
             .withMaxRetries(4)
             .backoff();
     while (true) {
-      try (Connection connection = dataSource.getConnection()) {
+      //This is not implemented as try-with-resources because it appears that 
try-with-resources is
+      //not correctly catching the PSQLException thrown by 
dataSource.getConnection()
+      Connection connection = null;
+      try {
+        connection = dataSource.getConnection();
         try (Statement statement = connection.createStatement()) {
           statement.execute(String.format("create table %s (%s)", tableName, 
fieldsList));
           return;
         }
       } catch (SQLException e) {
         exception = e;
+      } finally {
+        if (connection!=null){
+          connection.close();

Review Comment:
   Probably it is closing the connecting caused issue. dataSource owns a 
connection pool and manage the connections. Closing it pre-maturely may have 
caused racing conditions.



##########
sdks/java/io/common/src/test/java/org/apache/beam/sdk/io/common/DatabaseTestHelper.java:
##########
@@ -100,13 +100,21 @@ public static void createTable(
             .withMaxRetries(4)
             .backoff();
     while (true) {
-      try (Connection connection = dataSource.getConnection()) {
+      //This is not implemented as try-with-resources because it appears that 
try-with-resources is
+      //not correctly catching the PSQLException thrown by 
dataSource.getConnection()
+      Connection connection = null;
+      try {
+        connection = dataSource.getConnection();
         try (Statement statement = connection.createStatement()) {
           statement.execute(String.format("create table %s (%s)", tableName, 
fieldsList));
           return;
         }
       } catch (SQLException e) {
         exception = e;
+      } finally {
+        if (connection!=null){
+          connection.close();

Review Comment:
   Probably it is closing the connection caused issue. dataSource owns a 
connection pool and manage the connections. Closing it pre-maturely may have 
caused racing conditions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to