You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "bowenliang123 (via GitHub)" <gi...@apache.org> on 2023/11/20 06:32:52 UTC

[PR] Tolerate execeptions in scheduled tasks for ScheduledExecutorService [kyuubi]

bowenliang123 opened a new pull request, #5730:
URL: https://github.com/apache/kyuubi/pull/5730

   # :mag: Description
   ## Issue References ๐Ÿ”—
   <!-- Append the issue number after #. If there is no issue for you to link create one or -->
   <!-- If there are no issues to link, please provide details here. -->
   
   As the PR https://github.com/apache/kyuubi/pull/5727 fixed a problem caused by leaking exception in a scheduled task, the exception thrown should be properly handled to prevent suspension in `ScheduledExecutorService.scheduleWithFixedDelay`.
   
   ## Describe Your Solution ๐Ÿ”ง
   Introducing a `scheduleTolerableRunnableWithFixedDelay` method by catching possible exception in scheduled tasks.
   
   ## Types of changes :bookmark:
   <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
   - [ ] Bugfix (non-breaking change which fixes an issue)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   
   ## Test Plan ๐Ÿงช
   
   #### Behavior Without This Pull Request :coffin:
   
   
   #### Behavior With This Pull Request :tada:
   
   
   #### Related Unit Tests
   
   
   ---
   
   # Checklists
   ## ๐Ÿ“ Author Self Checklist
   <!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
   <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
   - [ ] My code follows the [style guidelines](https://kyuubi.readthedocs.io/en/master/contributing/code/style.html) of this project
   - [x] I have performed a self-review
   - [ ] I have commented my code, particularly in hard-to-understand areas
   - [ ] I have made corresponding changes to the documentation
   - [ ] My changes generate no new warnings
   - [ ] I have added tests that prove my fix is effective or that my feature works
   - [ ] New and existing unit tests pass locally with my changes
   - [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)
   
   ## ๐Ÿ“ Committer Pre-Merge Checklist
   
   - [ ] Pull request title is okay.
   - [ ] No license issues.
   - [ ] Milestone correctly set?
   - [ ] Test coverage is ok
   - [ ] Assignees are selected.
   - [ ] Minimum number of approvals
   - [ ] No changes are requested
   
   
   **Be nice. Be informative.**
   


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] Tolerate execeptions in scheduled tasks for ScheduledExecutorService [kyuubi]

Posted by "bowenliang123 (via GitHub)" <gi...@apache.org>.
bowenliang123 commented on PR #5730:
URL: https://github.com/apache/kyuubi/pull/5730#issuecomment-1818420417

   cc @turboFei @wForget 


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] Tolerate execeptions for periodical scheduled tasks [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #5730:
URL: https://github.com/apache/kyuubi/pull/5730#discussion_r1398877068


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/util/ThreadUtils.scala:
##########
@@ -109,4 +109,28 @@ object ThreadUtils extends Logging {
     thread.setUncaughtExceptionHandler(NamedThreadFactory.kyuubiUncaughtExceptionHandler)
     thread.start()
   }
+
+  /**
+   * Schedule a runnable to the scheduled executor service.
+   * The exceptions thrown in the runnable will be caught and logged.
+   */
+  def scheduleTolerableRunnableWithFixedDelay(
+      scheduler: ScheduledExecutorService,
+      runnable: Runnable,
+      initialDelay: Long,
+      delay: Long,
+      timeUnit: TimeUnit,
+      errorMessageHint: String): Unit = {
+    scheduler.scheduleWithFixedDelay(
+      () =>
+        try {
+          runnable.run()
+        } catch {
+          case e: Exception =>
+            error(s"Error in $errorMessageHint", e)

Review Comment:
   You can remove `errorMessageHint` variable.
   
   It is ok to use the thread name as hint.



##########
kyuubi-common/src/main/scala/org/apache/kyuubi/util/ThreadUtils.scala:
##########
@@ -109,4 +109,28 @@ object ThreadUtils extends Logging {
     thread.setUncaughtExceptionHandler(NamedThreadFactory.kyuubiUncaughtExceptionHandler)
     thread.start()
   }
+
+  /**
+   * Schedule a runnable to the scheduled executor service.
+   * The exceptions thrown in the runnable will be caught and logged.
+   */
+  def scheduleTolerableRunnableWithFixedDelay(
+      scheduler: ScheduledExecutorService,
+      runnable: Runnable,
+      initialDelay: Long,
+      delay: Long,
+      timeUnit: TimeUnit,
+      errorMessageHint: String): Unit = {
+    scheduler.scheduleWithFixedDelay(
+      () =>
+        try {
+          runnable.run()
+        } catch {
+          case e: Exception =>
+            error(s"Error in $errorMessageHint", e)

Review Comment:
   ```
   case e: Throwable => error(s"Uncaught exception in thread ${Thread.currentThread().getName}", t)
   ```



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] Tolerate execeptions in scheduled tasks for ScheduledExecutorService [kyuubi]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #5730:
URL: https://github.com/apache/kyuubi/pull/5730#issuecomment-1818418454

   ## [Codecov](https://app.codecov.io/gh/apache/kyuubi/pull/5730?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Comparison is base [(`71b0376`)](https://app.codecov.io/gh/apache/kyuubi/commit/71b03765779af43fec84d45a8e79a5a6fd3bb1d5?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 61.29% compared to head [(`87e2bf2`)](https://app.codecov.io/gh/apache/kyuubi/pull/5730?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 61.36%.
   
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #5730      +/-   ##
   ============================================
   + Coverage     61.29%   61.36%   +0.06%     
     Complexity       23       23              
   ============================================
     Files           607      607              
     Lines         35836    35881      +45     
     Branches       4917     4917              
   ============================================
   + Hits          21966    22018      +52     
   + Misses        11479    11470       -9     
   - Partials       2391     2393       +2     
   ```
   
   
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/kyuubi/pull/5730?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] Tolerate execeptions for periodical scheduled tasks [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei closed pull request #5730: Tolerate execeptions for periodical scheduled tasks
URL: https://github.com/apache/kyuubi/pull/5730


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] Tolerate execeptions for periodical scheduled tasks [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #5730:
URL: https://github.com/apache/kyuubi/pull/5730#discussion_r1398820709


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/util/ThreadUtils.scala:
##########
@@ -109,4 +109,28 @@ object ThreadUtils extends Logging {
     thread.setUncaughtExceptionHandler(NamedThreadFactory.kyuubiUncaughtExceptionHandler)
     thread.start()
   }
+
+  /**
+   * Schedule a runnable to the scheduled executor service.
+   * The exceptions thrown in the runnable will be caught and logged.
+   */
+  def scheduleTolerableRunnableWithFixedDelay(
+      scheduler: ScheduledExecutorService,
+      runnable: Runnable,
+      initialDelay: Long,
+      delay: Long,
+      timeUnit: TimeUnit,
+      errorMessageHint: String): Unit = {
+    scheduler.scheduleWithFixedDelay(
+      () =>
+        try {
+          runnable.run()
+        } catch {
+          case e: Exception =>
+            error(s"Error in $errorMessageHint", e)

Review Comment:
   ```
   case e: Throwable => error(s"Uncaught exception in thread ${Thread.currentThread().getName}", t)
   ```



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] Tolerate execeptions for periodical scheduled tasks [kyuubi]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #5730:
URL: https://github.com/apache/kyuubi/pull/5730#issuecomment-1818987329

   thanks, merged to master and branch-1.8


-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] Tolerate execeptions for periodical scheduled tasks [kyuubi]

Posted by "bowenliang123 (via GitHub)" <gi...@apache.org>.
bowenliang123 commented on code in PR #5730:
URL: https://github.com/apache/kyuubi/pull/5730#discussion_r1398885177


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/util/ThreadUtils.scala:
##########
@@ -109,4 +109,28 @@ object ThreadUtils extends Logging {
     thread.setUncaughtExceptionHandler(NamedThreadFactory.kyuubiUncaughtExceptionHandler)
     thread.start()
   }
+
+  /**
+   * Schedule a runnable to the scheduled executor service.
+   * The exceptions thrown in the runnable will be caught and logged.
+   */
+  def scheduleTolerableRunnableWithFixedDelay(
+      scheduler: ScheduledExecutorService,
+      runnable: Runnable,
+      initialDelay: Long,
+      delay: Long,
+      timeUnit: TimeUnit,
+      errorMessageHint: String): Unit = {
+    scheduler.scheduleWithFixedDelay(
+      () =>
+        try {
+          runnable.run()
+        } catch {
+          case e: Exception =>
+            error(s"Error in $errorMessageHint", e)

Review Comment:
   Sure, it's much more elegant.



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


Re: [PR] Tolerate execeptions for periodical scheduled tasks [kyuubi]

Posted by "bowenliang123 (via GitHub)" <gi...@apache.org>.
bowenliang123 commented on code in PR #5730:
URL: https://github.com/apache/kyuubi/pull/5730#discussion_r1398855696


##########
kyuubi-common/src/main/scala/org/apache/kyuubi/util/ThreadUtils.scala:
##########
@@ -109,4 +109,28 @@ object ThreadUtils extends Logging {
     thread.setUncaughtExceptionHandler(NamedThreadFactory.kyuubiUncaughtExceptionHandler)
     thread.start()
   }
+
+  /**
+   * Schedule a runnable to the scheduled executor service.
+   * The exceptions thrown in the runnable will be caught and logged.
+   */
+  def scheduleTolerableRunnableWithFixedDelay(
+      scheduler: ScheduledExecutorService,
+      runnable: Runnable,
+      initialDelay: Long,
+      delay: Long,
+      timeUnit: TimeUnit,
+      errorMessageHint: String): Unit = {
+    scheduler.scheduleWithFixedDelay(
+      () =>
+        try {
+          runnable.run()
+        } catch {
+          case e: Exception =>
+            error(s"Error in $errorMessageHint", e)

Review Comment:
   Thanks. Adopted.



-- 
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: notifications-unsubscribe@kyuubi.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org