grim/convey

Improve inline docs around cleanup.
cleanup-on-signal
2017-10-13, Eric Fritz
4678efc2644b
Parents 137e9068c5f0
Children fcbb5bf74b5d
Improve inline docs around cleanup.
--- a/docker/run.go Fri Oct 13 12:27:28 2017 -0500
+++ b/docker/run.go Fri Oct 13 17:58:23 2017 -0500
@@ -179,8 +179,12 @@
return err
}
- // Remove the script on defer OR on signal exit (first one to happen)
- defer st.CleanupList.Add(func() { os.Remove(script.Name()) })()
+ // Be sure to clean up the script on app exit
+ cleanupFn := st.CleanupList.Add(func() { os.Remove(script.Name()) })
+
+ // Call cleanup function on defer, which will may may instead be called
+ // if the cleanup thread traps a signal.
+ defer cleanupFn()
scriptFile, entryPoint, commandArg, err = r.writeScript(st, script, fullEnv)
if err != nil {
--- a/plans/plans.go Fri Oct 13 12:27:28 2017 -0500
+++ b/plans/plans.go Fri Oct 13 17:58:23 2017 -0500
@@ -96,8 +96,12 @@
logger := logging.NewAdapter(path)
planEnv := environment.Merge(env, p.Environment)
- // Teardown plan on defer OR on signal exit (first one to happen)
- defer st.CleanupList.Add(func() { p.teardown(logger, st) })()
+ // Teardown plan on defer on app exit
+ cleanupFn := st.CleanupList.Add(func() { p.teardown(logger, st) })
+
+ // Call cleanup function on defer, which will may may instead be called
+ // if the cleanup thread traps a signal.
+ defer cleanupFn()
if err := p.setup(logger, st); err != nil {
return err