Github user chtyim commented on a diff in the pull request:

    https://github.com/apache/twill/pull/4#discussion_r76317898
  
    --- Diff: 
twill-core/src/main/java/org/apache/twill/internal/TwillContainerLauncher.java 
---
    @@ -220,5 +250,31 @@ public ContainerLiveNodeData getLiveNodeData() {
         public void kill() {
           processController.cancel();
         }
    +
    +    private void killAndWait(int maxWaitSecs) {
    +      Stopwatch watch = new Stopwatch();
    +      watch.start();
    +      int tries = 0;
    +      while (watch.elapsedTime(TimeUnit.SECONDS) < maxWaitSecs) {
    +        // Kill the application
    +        try {
    +          ++tries;
    +          kill();
    +        } catch (Exception e) {
    +          LOG.error("Exception while killing runnable {}, instance {}", 
runnable, instanceId, e);
    +        }
    +
    +        // Wait on the shutdownLatch,
    +        // if the runnable has stopped then the latch will be count down 
by completed() method
    +        if (Uninterruptibles.awaitUninterruptibly(shutdownLatch, 10, 
TimeUnit.SECONDS)) {
    +          // Runnable has stopped now
    +          return;
    +        }
    +      }
    +
    +      // Timeout reached, runnable has not stopped
    +      LOG.error("Failed to kill runnable {}, instance {} after {} tries", 
runnable, instanceId, tries);
    --- End diff --
    
    Showing the number of tries is quite artificial since the retry is based on 
time. I think it's better to just say failed to kill after n seconds.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to