!20 HotFix: fix panic when user knock ctrl+c in pull, push and save command

From: @DCCooper
Reviewed-by: @jingxiaolu
Signed-off-by: @jingxiaolu
This commit is contained in:
openeuler-ci-bot 2020-11-10 16:37:58 +08:00 committed by Gitee
commit 30ee9acf11
5 changed files with 142 additions and 3 deletions

View File

@ -1 +1 @@
0.9.4-1
0.9.4-2

View File

@ -1 +1 @@
9f2eac8f0045f78872350da89a871f9c6d609a24
95f55a42ca8f886a540ee792a591e16a96058da0

View File

@ -2,7 +2,7 @@
Name: isula-build
Version: 0.9.4
Release: 1
Release: 2
Summary: A tool to build container images
License: Mulan PSL V2
URL: https://gitee.com/openeuler/isula-build
@ -81,6 +81,9 @@ fi
/usr/share/bash-completion/completions/isula-build
%changelog
* Tue Nov 10 2020 lixiang <lixiang172@huawei.com> - 0.9.4-2
- Fix panic when user knock ctrl-c in pull/push/save command
* Fri Nov 06 2020 lixiang <lixiang172@huawei.com> - 0.9.4-1
- Bump version to 0.9.4

View File

@ -0,0 +1,135 @@
From a33d6ae4fb22a4d72d714733b3045272e050c0d7 Mon Sep 17 00:00:00 2001
From: xingweizheng 00591739 <xingweizheng@huawei.com>
Date: Mon, 9 Nov 2020 13:54:57 +0800
Subject: [PATCH] fix panic when user knock ctrl+c when pull, push and save
---
daemon/pull.go | 24 +++++++++---------------
daemon/push.go | 24 +++++++++---------------
daemon/save.go | 29 +++++++++--------------------
3 files changed, 27 insertions(+), 50 deletions(-)
diff --git a/daemon/pull.go b/daemon/pull.go
index f9dee3e..56be755 100644
--- a/daemon/pull.go
+++ b/daemon/pull.go
@@ -59,23 +59,17 @@ func (b *Backend) Pull(req *pb.PullRequest, stream pb.Control_PullServer) error
eg.Go(pullMessageHandler(stream, opt.logger))
errC := make(chan error, 1)
- go func() { errC <- eg.Wait() }()
+ errC <- eg.Wait()
defer close(errC)
- select {
- case err2 := <-errC:
- if err2 != nil {
- return err2
- }
- case _, ok := <-stream.Context().Done():
- if !ok {
- logrus.WithField(util.LogKeySessionID, opt.pullID).Info("Channel stream done closed")
- return nil
- }
- err := egCtx.Err()
- if err != nil && err != context.Canceled {
- logrus.WithField(util.LogKeySessionID, opt.pullID).Warnf("Stream closed with: %v", err)
- }
+ err, ok := <-errC
+ if !ok {
+ logrus.WithField(util.LogKeySessionID, opt.pullID).Info("Channel errC closed")
+ return nil
+ }
+ if err != nil {
+ logrus.WithField(util.LogKeySessionID, opt.pullID).Warnf("Stream closed with: %v", err)
+ return err
}
return nil
diff --git a/daemon/push.go b/daemon/push.go
index 712062e..ea5e47c 100644
--- a/daemon/push.go
+++ b/daemon/push.go
@@ -63,23 +63,17 @@ func (b *Backend) Push(req *pb.PushRequest, stream pb.Control_PushServer) error
eg.Go(pushMessageHandler(stream, opt.logger))
errC := make(chan error, 1)
- go func() { errC <- eg.Wait() }()
+ errC <- eg.Wait()
defer close(errC)
- select {
- case err2 := <-errC:
- if err2 != nil {
- return err2
- }
- case _, ok := <-stream.Context().Done():
- if !ok {
- logrus.WithField(util.LogKeySessionID, opt.pushID).Info("Channel stream done closed")
- return nil
- }
- err := egCtx.Err()
- if err != nil && err != context.Canceled {
- logrus.WithField(util.LogKeySessionID, opt.pushID).Warnf("Stream closed with: %v", err)
- }
+ err, ok := <-errC
+ if !ok {
+ logrus.WithField(util.LogKeySessionID, opt.pushID).Info("Channel errC closed")
+ return nil
+ }
+ if err != nil {
+ logrus.WithField(util.LogKeySessionID, opt.pushID).Warnf("Stream closed with: %v", err)
+ return err
}
return nil
diff --git a/daemon/save.go b/daemon/save.go
index 13ca8cd..156a1c2 100644
--- a/daemon/save.go
+++ b/daemon/save.go
@@ -102,33 +102,22 @@ func (b *Backend) Save(req *pb.SaveRequest, stream pb.Control_SaveServer) (err e
}
ctx := context.WithValue(stream.Context(), util.LogFieldKey(util.LogKeySessionID), opts.saveID)
- eg, egCtx := errgroup.WithContext(ctx)
+ eg, _ := errgroup.WithContext(ctx)
eg.Go(exportHandler(ctx, stream, opts))
eg.Go(messageHandler(stream, opts.logger))
errC := make(chan error, 1)
- go func() { errC <- eg.Wait() }()
+ errC <- eg.Wait()
defer close(errC)
- select {
- case err, ok = <-errC:
- if !ok {
- opts.logEntry.Info("Channel errC closed")
- return nil
- }
- if err != nil {
- return err
- }
- case _, ok := <-stream.Context().Done():
- if !ok {
- opts.logEntry.Info("Channel stream done closed")
- return nil
- }
- err = egCtx.Err()
- if err != nil && err != context.Canceled {
- opts.logEntry.Infof("Stream closed with: %v", err)
- }
+ err, ok = <-errC
+ if !ok {
+ opts.logEntry.Info("Channel errC closed")
+ return nil
+ }
+ if err != nil {
+ return err
}
return nil
--
1.8.3.1

View File

@ -8,3 +8,4 @@ patch/0037-isula-build-fix-goroutine-leak-problem.patch
#patch/0039-bugfix-fix-build-hang-problem-when-error-happened-be.patch
#patch/0040-isula-build-change-default-healthcheck-timeout-to-20.patch
#patch/0041-isula-build-add-t-shortname-for-tag-and-remove-it-fr.patch
patch/0065-fix-panic-when-user-knock-ctrl-c-when-pull-push-and-.patch