From f110f84958734365dd399899c8cc0e99fd8bbce3 Mon Sep 17 00:00:00 2001 From: Travis Ralston <travpc@gmail.com> Date: Thu, 26 Mar 2020 16:01:39 -0600 Subject: [PATCH] Move stop and import channel update closures into more relevant places --- cmd/media_repo/main.go | 2 +- controllers/data_controller/import_controller.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/media_repo/main.go b/cmd/media_repo/main.go index 5b82f83f..ee80e9df 100644 --- a/cmd/media_repo/main.go +++ b/cmd/media_repo/main.go @@ -79,10 +79,10 @@ func main() { // Set up a listener for SIGINT stop := make(chan os.Signal) - defer close(stop) signal.Notify(stop, os.Interrupt, os.Kill) selfStop := false go func() { + defer close(stop) <-stop selfStop = true diff --git a/controllers/data_controller/import_controller.go b/controllers/data_controller/import_controller.go index be6db5a1..05003e03 100644 --- a/controllers/data_controller/import_controller.go +++ b/controllers/data_controller/import_controller.go @@ -54,7 +54,6 @@ func StartImport(data io.Reader, ctx rcontext.RequestContext) (*types.Background // Start the import and send it its first update updateChan := make(chan *importUpdate) - defer close(updateChan) go doImport(updateChan, task.ID, importId, ctx) openImports.Store(importId, updateChan) updateChan <- &importUpdate{stop: false, fileMap: results} @@ -131,6 +130,8 @@ func processArchive(data io.Reader) (map[string]*bytes.Buffer, error) { } func doImport(updateChannel chan *importUpdate, taskId int, importId string, ctx rcontext.RequestContext) { + defer close(updateChannel) + // Use a new context in the goroutine ctx.Context = context.Background() -- GitLab