Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: grpc/prpc/client.go

Issue 2360403002: pRPC: Retry on certain transient HTTP failures. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | grpc/prpc/client_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package prpc 5 package prpc
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 if codeHeader == "" { 222 if codeHeader == "" {
223 // Not a valid pRPC response. 223 // Not a valid pRPC response.
224 body := buf.String() 224 body := buf.String()
225 bodySize := c.ErrBodySize 225 bodySize := c.ErrBodySize
226 if bodySize <= 0 { 226 if bodySize <= 0 {
227 bodySize = 256 227 bodySize = 256
228 } 228 }
229 if len(body) > bodySize { 229 if len(body) > bodySize {
230 body = body[:bodySize] + "..." 230 body = body[:bodySize] + "..."
231 } 231 }
232 » » » » return fmt.Errorf("HTTP %d: no gRPC code. Body: %q", res.StatusCode, body) 232 » » » » err := fmt.Errorf("HTTP %d: no gRPC code. Body: %q", res.StatusCode, body)
233
234 » » » » // Some HTTP codes are returned directly by host ing platforms (e.g.,
235 » » » » // AppEngine), and should be automatically retri ed even if a gRPC code
236 » » » » // header is not supplied.
237 » » » » switch res.StatusCode {
238 » » » » case http.StatusInternalServerError, http.Status ServiceUnavailable:
239 » » » » » err = errors.WrapTransient(err)
240 » » » » }
241 » » » » return err
233 } 242 }
234 243
235 codeInt, err := strconv.Atoi(codeHeader) 244 codeInt, err := strconv.Atoi(codeHeader)
236 if err != nil { 245 if err != nil {
237 // Not a valid pRPC response. 246 // Not a valid pRPC response.
238 return fmt.Errorf("invalid grpc code %q: %s", co deHeader, err) 247 return fmt.Errorf("invalid grpc code %q: %s", co deHeader, err)
239 } 248 }
240 249
241 code := codes.Code(codeInt) 250 code := codes.Code(codeInt)
242 if code != codes.OK { 251 if code != codes.OK {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 if len(h) == 0 { 332 if len(h) == 0 {
324 return nil 333 return nil
325 } 334 }
326 335
327 md := make(metadata.MD, len(h)) 336 md := make(metadata.MD, len(h))
328 for k, v := range h { 337 for k, v := range h {
329 md[strings.ToLower(k)] = v 338 md[strings.ToLower(k)] = v
330 } 339 }
331 return md 340 return md
332 } 341 }
OLDNEW
« no previous file with comments | « no previous file | grpc/prpc/client_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698