You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "fsk119 (via GitHub)" <gi...@apache.org> on 2023/03/08 04:16:07 UTC

[GitHub] [flink] fsk119 opened a new pull request, #22127: [FLINK-31351][sql-gateway] Don't stop the stuck thread by force

fsk119 opened a new pull request, #22127:
URL: https://github.com/apache/flink/pull/22127

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   *We should not stop the thread by force because it may cause an inconsistent state. So we just notify the users it has the possibility to cause resource leak. *
   
   
   


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on a diff in pull request #22127: [FLINK-31351][sql-gateway] Don't stop the stuck thread by force

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #22127:
URL: https://github.com/apache/flink/pull/22127#discussion_r1129192778


##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/operation/OperationManagerTest.java:
##########
@@ -64,8 +66,8 @@ public class OperationManagerTest {
             new ExecutorThreadFactory(
                     "SqlGatewayService Test Pool", IgnoreExceptionHandler.INSTANCE);
 
-    @BeforeAll
-    public static void setUp() {
+    @BeforeEach
+    public void setUp() {

Review Comment:
   nit: modifier could be package private
   ```suggestion
       void setUp() {
   ```



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/operation/OperationManagerTest.java:
##########
@@ -129,29 +135,54 @@ public void testCancelOperation() throws Exception {
     }
 
     @Test
-    public void testCancelOperationByForce() throws Exception {
-        AtomicReference<Throwable> exception = new AtomicReference<>(null);
+    public void testCancelUninterruptedOperation() throws Exception {

Review Comment:
   nit: modifier could be package private
   ```suggestion
       void testCancelUninterruptedOperation() throws Exception {
   ```



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on pull request #22127: [FLINK-31351][sql-gateway] Don't stop the stuck thread by force

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #22127:
URL: https://github.com/apache/flink/pull/22127#issuecomment-1459900664

   lgtm, just a couple of minor comments


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] fsk119 closed pull request #22127: [FLINK-31351][sql-gateway] Don't stop the stuck thread by force

Posted by "fsk119 (via GitHub)" <gi...@apache.org>.
fsk119 closed pull request #22127: [FLINK-31351][sql-gateway] Don't stop the stuck thread by force
URL: https://github.com/apache/flink/pull/22127


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] lincoln-lil commented on a diff in pull request #22127: [FLINK-31351][sql-gateway] Don't stop the stuck thread by force

Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil commented on code in PR #22127:
URL: https://github.com/apache/flink/pull/22127#discussion_r1129043195


##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/operation/OperationManager.java:
##########
@@ -183,12 +190,15 @@ public ResultSet fetchResults(
     /** Closes the {@link OperationManager} and all operations. */
     public void close() {
         stateLock.writeLock().lock();
+        Exception closeException = null;
         try {
             isRunning = false;
-            for (Operation operation : submittedOperations.values()) {
-                operation.close();
-            }
+            List<Operation> copiedOperations = new ArrayList<>(submittedOperations.values());

Review Comment:
   we can remove this copy and move the 'clear()' to finally clause



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/operation/OperationManager.java:
##########
@@ -30,26 +30,33 @@
 import org.apache.flink.table.gateway.api.utils.SqlGatewayException;
 import org.apache.flink.table.gateway.service.result.NotReadyResult;
 import org.apache.flink.table.gateway.service.result.ResultFetcher;
+import org.apache.flink.table.gateway.service.utils.SqlCancelException;
 import org.apache.flink.table.gateway.service.utils.SqlExecutionException;
+import org.apache.flink.util.IOUtils;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.lang.reflect.Field;
 import java.time.Duration;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.FutureTask;
 import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.function.Function;
 import java.util.function.Supplier;
 
+import static org.apache.flink.shaded.guava30.com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;

Review Comment:
   nit: just use normal import?



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] snuyanzin commented on a diff in pull request #22127: [FLINK-31351][sql-gateway] Don't stop the stuck thread by force

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #22127:
URL: https://github.com/apache/flink/pull/22127#discussion_r1129193253


##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/operation/OperationManagerTest.java:
##########
@@ -129,29 +135,54 @@ public void testCancelOperation() throws Exception {
     }
 
     @Test
-    public void testCancelOperationByForce() throws Exception {
-        AtomicReference<Throwable> exception = new AtomicReference<>(null);
+    public void testCancelUninterruptedOperation() throws Exception {
+        AtomicReference<Boolean> isRunning = new AtomicReference<>(false);
         OperationHandle operationHandle =
                 operationManager.submitOperation(
                         () -> {
-                            try {
-                                // mock cpu busy task that doesn't interrupt system call
-                                while (true) {}
-                            } catch (Throwable t) {
-                                exception.set(t);
-                                throw t;
+                            // mock cpu busy task that doesn't interrupt system call
+                            while (true) {
+                                isRunning.compareAndSet(false, true);
                             }
                         });
-
-        threadFactory.newThread(() -> operationManager.cancelOperation(operationHandle)).start();
-        operationManager.awaitOperationTermination(operationHandle);
+        CommonTestUtils.waitUtil(
+                isRunning::get, Duration.ofSeconds(10), "Failed to start up the task.");
+        assertThatThrownBy(() -> operationManager.cancelOperation(operationHandle))
+                .satisfies(
+                        FlinkAssertions.anyCauseMatches(
+                                SqlCancelException.class,
+                                String.format(
+                                        "Operation '%s' did not react to \"Future.cancel(true)\" and "
+                                                + "is stuck for %s seconds in method.\n",
+                                        operationHandle, 5)));
 
         assertThat(operationManager.getOperationInfo(operationHandle).getStatus())
                 .isEqualTo(OperationStatus.CANCELED);
+    }
+
+    @Test
+    public void testCloseUninterruptedOperation() throws Exception {

Review Comment:
   nit: modifier could be package private
   ```suggestion
       void testCloseUninterruptedOperation() throws Exception {
   ```



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] fsk119 commented on pull request #22127: [FLINK-31351][sql-gateway] Don't stop the stuck thread by force

Posted by "fsk119 (via GitHub)" <gi...@apache.org>.
fsk119 commented on PR #22127:
URL: https://github.com/apache/flink/pull/22127#issuecomment-1460033521

   Thanks a lot for @snuyanzin review. Because all comments are in about the `public` modifier, so I fix the comments locally.
   
   Merging...


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] flinkbot commented on pull request #22127: [FLINK-31351][sql-gateway] Don't stop the stuck thread by force

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #22127:
URL: https://github.com/apache/flink/pull/22127#issuecomment-1459422574

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "2331a3f92229c2cd6dfd0f2dc418f77fbc83e4c3",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "2331a3f92229c2cd6dfd0f2dc418f77fbc83e4c3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 2331a3f92229c2cd6dfd0f2dc418f77fbc83e4c3 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org