From 5caa6cda6f710f87f0b6d77b01b21d1648aec2af Mon Sep 17 00:00:00 2001 From: dongzhihong Date: Mon, 3 Jul 2017 14:42:53 +0800 Subject: [PATCH] "fix go client get params channel return bug" --- go/pserver/client.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/go/pserver/client.go b/go/pserver/client.go index 6938b9d5ce6f6..a7bbe3e277e52 100644 --- a/go/pserver/client.go +++ b/go/pserver/client.go @@ -136,9 +136,10 @@ func (c *Client) SendGrads(grads []Gradient) error { } recv := 0 + var errs []error for err := range errCh { if err != nil { - return err + errs = append(errs, err) } recv++ @@ -146,6 +147,9 @@ func (c *Client) SendGrads(grads []Gradient) error { break } } + if len(errs) != 0 { + return errs[0] + } return nil } @@ -182,18 +186,23 @@ func (c *Client) GetParams(names []string) ([]Parameter, error) { } var rs results + var errs []error recv := 0 for r := range rCh { if r.err != nil { - return nil, r.err + errs = append(errs, r.err) + } else { + rs = append(rs, r) } - rs = append(rs, r) recv++ if recv == len(names) { break } } + if len(errs) != 0 { + return nil, errs[0] + } sort.Sort(rs) ps := make([]Parameter, len(rs)) @@ -214,9 +223,10 @@ func (c *Client) Save(path string) error { } recv := 0 + var errs []error for err := range errCh { if err != nil { - return err + errs = append(errs, err) } recv++ @@ -224,6 +234,9 @@ func (c *Client) Save(path string) error { break } } + if len(errs) != 0 { + return errs[0] + } // TODO(helin): there will be many files under path, need to // merge them into a single file.