From d6596792386b69971b145470d81a4a46ee748a97 Mon Sep 17 00:00:00 2001 From: Alex Zylman Date: Thu, 4 May 2017 22:32:58 -0700 Subject: [PATCH] fix panics while publishing (#191) --- tools/common/lib.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/common/lib.go b/tools/common/lib.go index a6a391d4..257ee137 100644 --- a/tools/common/lib.go +++ b/tools/common/lib.go @@ -1274,17 +1274,21 @@ func Publish(c *cli.Context, cClient ccli.Client) { break } + // Increment the WaitGroup before the publish to make sure that + // we'll never call Done on the WaitGroup before we've called Add. + receiptWg.Add(1) id, err = publisher.PublishAsync(&ccli.PublisherMessage{ Data: line, }, receiptCh) if err != nil { + // If the publish errored, we never actually sent a receipt down the channel. + receiptWg.Done() fmt.Fprintf(os.Stderr, "%v\n", err) break } fmt.Fprintf(os.Stdout, "Local publish ID: %s\n", id) - receiptWg.Add(1) } if !common.AwaitWaitGroup(&receiptWg, time.Minute) {