From 480d613b62c81d49942ddbc526005deaa50db546 Mon Sep 17 00:00:00 2001 From: Chowlz Date: Mon, 8 Jun 2020 12:27:40 -0700 Subject: [PATCH] Disable signal handlers on AWS lambdas via env var (#462) * Disable handle-sigint! when BABASHKA_DISABLE_PIPE_SIGNAL_HANDLER is true This allows babashka to be run in an AWS lambda. * Rename BABASHKA_DISABLE_PIPE_SIGNAL_HANDLER to BABASHKA_DISABLE_SIGNAL_HANDLERS Any signal handler used in AWS lambdas will not work. This simplifies/shortens the naming of the env var. --- README.md | 4 ++-- src/babashka/impl/pipe_signal_handler.clj | 2 +- src/babashka/impl/sigint_handler.clj | 13 +++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b30e4dc8..47e2cbb0 100644 --- a/README.md +++ b/README.md @@ -803,8 +803,8 @@ repo](https://github.com/babashka/babashka.pods). ## Package babashka script as a AWS Lambda AWS Lambda runtime doesn't support signals, therefore babashka has to disable -handling of the SIGPIPE. This can be done by setting -`BABASHKA_DISABLE_PIPE_SIGNAL_HANDLER` to `true`. +handling of SIGINT and SIGPIPE. This can be done by setting +`BABASHKA_DISABLE_SIGNAL_HANDLERS` to `true`. ## Articles, podcasts and videos diff --git a/src/babashka/impl/pipe_signal_handler.clj b/src/babashka/impl/pipe_signal_handler.clj index e1bf83b2..3b5fed21 100644 --- a/src/babashka/impl/pipe_signal_handler.clj +++ b/src/babashka/impl/pipe_signal_handler.clj @@ -9,7 +9,7 @@ (identical? :PIPE @pipe-state)) (defn handle-pipe! [] - (when-not (= "true" (System/getenv "BABASHKA_DISABLE_PIPE_SIGNAL_HANDLER")) + (when-not (= "true" (System/getenv "BABASHKA_DISABLE_SIGNAL_HANDLERS")) (Signal/handle (Signal. "PIPE") (reify SignalHandler diff --git a/src/babashka/impl/sigint_handler.clj b/src/babashka/impl/sigint_handler.clj index 9708bc59..508e01b2 100644 --- a/src/babashka/impl/sigint_handler.clj +++ b/src/babashka/impl/sigint_handler.clj @@ -6,9 +6,10 @@ (set! *warn-on-reflection* true) (defn handle-sigint! [] - (Signal/handle - (Signal. "INT") - (reify SignalHandler - (handle [_ _] - ;; This is needed to run shutdown hooks on interrupt, System/exit triggers those - (System/exit 0))))) + (when-not (= "true" (System/getenv "BABASHKA_DISABLE_SIGNAL_HANDLERS")) + (Signal/handle + (Signal. "INT") + (reify SignalHandler + (handle [_ _] + ;; This is needed to run shutdown hooks on interrupt, System/exit triggers those + (System/exit 0))))))