Skip to content

Commit de082e5

Browse files
committed
ensure we cancel child context when reading grpc
Signed-off-by: Avi Deitcher <[email protected]>
1 parent e4e05c6 commit de082e5

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

content/proxy/content_reader.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ func (ra *remoteReaderAt) ReadAt(p []byte, off int64) (n int, err error) {
4040
Offset: off,
4141
Size_: int64(len(p)),
4242
}
43-
rc, err := ra.client.Read(ra.ctx, rr)
43+
// we need a child context with cancel, or the eventually called
44+
// grpc.NewStream will leak the goroutine until the whole thing is cleared.
45+
// See comment at https://godoc.org/google.golang.org/grpc#ClientConn.NewStream
46+
childCtx, cancel := context.WithCancel(ra.ctx)
47+
// we MUST cancel the child context; see comment above
48+
defer cancel()
49+
rc, err := ra.client.Read(childCtx, rr)
4450
if err != nil {
4551
return 0, err
4652
}

0 commit comments

Comments
 (0)