[ARVADOS] updated: 50484a71693dd3458b8d2323a8c4e118f37121a9

git at public.curoverse.com git at public.curoverse.com
Tue Oct 27 10:22:21 EDT 2015


Summary of changes:
 sdk/go/crunchrunner/crunchrunner.go | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

       via  50484a71693dd3458b8d2323a8c4e118f37121a9 (commit)
      from  0fa7cd5bfdab924f316046f923aec282b699d8a1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 50484a71693dd3458b8d2323a8c4e118f37121a9
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Tue Oct 27 10:22:10 2015 -0400

    7582: Fixup concurrency around signal catching and forwarding.

diff --git a/sdk/go/crunchrunner/crunchrunner.go b/sdk/go/crunchrunner/crunchrunner.go
index 02f2be4..8e24e18 100644
--- a/sdk/go/crunchrunner/crunchrunner.go
+++ b/sdk/go/crunchrunner/crunchrunner.go
@@ -124,9 +124,9 @@ func setupCommand(cmd *exec.Cmd, taskp TaskDef, outdir string, replacements map[
 	return stdin, stdout, nil
 }
 
+// Set up signal handlers.  Go sends signal notifications to a "signal
+// channel".
 func setupSignals(cmd *exec.Cmd) chan os.Signal {
-	// Set up signal handlers
-	// Forward SIGINT, SIGTERM and SIGQUIT to inner process
 	sigChan := make(chan os.Signal, 1)
 	signal.Notify(sigChan, syscall.SIGTERM)
 	signal.Notify(sigChan, syscall.SIGINT)
@@ -234,24 +234,28 @@ func runner(api IArvadosClient,
 	log.Printf("Running %v%v%v", cmd.Args, stdin, stdout)
 
 	var caughtSignal os.Signal
-	{
-		sigChan := setupSignals(cmd)
-		defer signal.Stop(sigChan)
+	sigChan := setupSignals(cmd)
 
-		err = cmd.Start()
-		if err != nil {
-			return TempFail{err}
+	err = cmd.Start()
+	if err != nil {
+		signal.Stop(sigChan)
+		return TempFail{err}
+	}
+
+	finishedSignalNotify := make(chan struct{})
+	go func(sig <-chan os.Signal) {
+		for sig := range sig {
+			caughtSignal = sig
+			cmd.Process.Signal(caughtSignal)
 		}
+		close(finishedSignalNotify)
+	}(sigChan)
 
-		go func(sig <-chan os.Signal) {
-			for sig := range sig {
-				caughtSignal = sig
-				cmd.Process.Signal(caughtSignal)
-			}
-		}(sigChan)
+	err = cmd.Wait()
+	signal.Stop(sigChan)
 
-		err = cmd.Wait()
-	}
+	close(sigChan)
+	<-finishedSignalNotify
 
 	if caughtSignal != nil {
 		log.Printf("Caught signal %v", caughtSignal)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list