[ 
https://issues.apache.org/jira/browse/STORM-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14033089#comment-14033089
 ] 

ASF GitHub Bot commented on STORM-183:
--------------------------------------

Github user Parth-Brahmbhatt commented on a diff in the pull request:

    https://github.com/apache/incubator-storm/pull/143#discussion_r13833623
  
    --- Diff: storm-core/src/clj/backtype/storm/util.clj ---
    @@ -388,13 +388,51 @@
         (catch IOException e
           (log-message "Could not extract " dir " from " jarpath))))
     
    -(defn ensure-process-killed! [pid]
    +(defn sleep-secs [secs]
    +  (when (pos? secs)
    +    (Time/sleep (* (long secs) 1000))))
    +
    +(defn sleep-until-secs [target-secs]
    +  (Time/sleepUntil (* (long target-secs) 1000)))
    +
    +(def ^:const sig-kill 9)
    +
    +(def ^:const sig-term 15)
    +
    +(defn send-signal-to-process
    +  [pid signum]
    +  (try-cause
    +    (exec-command! (str (if on-windows?
    +                          (if (== signum sig-kill) "taskkill /f /pid " 
"taskkill /pid ")
    +                          (str "kill -" signum " "))
    +                     pid))
    +    (catch ExecuteException e
    +      (log-message "Error when trying to kill " pid ". Process is probably 
already dead."))))
    +
    +(defn force-kill-process
    +  [pid]
    +  (send-signal-to-process pid sig-kill))
    +
    +(defn kill-process-with-sig-term
    +  [pid]
    +  (send-signal-to-process pid sig-term))
    +
    +(defn ensure-process-killed!
    +  [pid]
       ;; TODO: should probably do a ps ax of some sort to make sure it was 
killed
       (try-cause
    -    (exec-command! (str (if on-windows? "taskkill /f /pid " "kill -9 ") 
pid))
    +    (kill-process-with-sig-term pid)
         (catch ExecuteException e
           (log-message "Error when trying to kill " pid ". Process is probably 
already dead."))))
     
    +(defn add-shutdown-hook-with-force-kill-in-1-sec
    +  "adds the user supplied function as a shutdown hook for cleanup.
    +   Also adds a function that sleeps for a second and then sends kill -9 to 
process to avoid any zombie process in case
    +   cleanup function hangs."
    +  [func]
    +  (.addShutdownHook (Runtime/getRuntime) (Thread. #((func)
    +                                                     (sleep-secs 1)
    +                                                     (force-kill-process 
(process-pid))))))
    --- End diff --
    
    done.


> Supervisor/worker shutdown hook should be called in distributed mode.
> ---------------------------------------------------------------------
>
>                 Key: STORM-183
>                 URL: https://issues.apache.org/jira/browse/STORM-183
>             Project: Apache Storm (Incubating)
>          Issue Type: Bug
>            Reporter: caofangkun
>            Priority: Minor
>         Attachments: STORM-183-1.patch
>
>
> if the process is killed forcefully from the OS or if it's crashing due to 
> resource issues (e.g., out of memory), shutdown hooks won't be invoked.
> -TERM (15) 
> The process is requested to stop running; it should try to exit cleanly 
> -KILL (9) 
> The process will be killed by the kernel; this signal cannot be ignored.
> So should we better use 'kill -15' ?
> See:
> https://github.com/apache/incubator-storm/blob/master/storm-core/src/clj/backtype/storm/util.clj#L392
> https://github.com/apache/incubator-storm/blob/master/storm-core/src/clj/backtype/storm/daemon/supervisor.clj#L175
> will never be called for supervisor:
> https://github.com/apache/incubator-storm/blob/master/storm-core/src/clj/backtype/storm/daemon/supervisor.clj#L396
> will never be called for worker:
> https://github.com/apache/incubator-storm/blob/master/storm-core/src/clj/backtype/storm/daemon/worker.clj#L421
> We'd better add something like :
> (.addShutdownHook (Runtime/getRuntime) (Thread. (fn [] (.shutdown mk-sv)))))) 
>  ?



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to