Skip to content

Commit

Permalink
close the reqCh in Close() to avoid leaking goroutines (#1687)
Browse files Browse the repository at this point in the history
fixes #1681
  • Loading branch information
harshavardhana committed Aug 2, 2022
1 parent caf54c4 commit b65486d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api-get-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (c *Client) GetObject(ctx context.Context, bucketName, objectName string, o

// This routine feeds partial object data as and when the caller reads.
go func() {
defer close(reqCh)
defer close(resCh)
defer func() {
// Close the http response body before returning.
Expand Down Expand Up @@ -616,6 +615,9 @@ func (o *Object) Close() (err error) {
// Close successfully.
o.cancel()

// Close the request channel to indicate the internal go-routine to exit.
close(o.reqCh)

// Save for future operations.
errMsg := "Object is already closed. Bad file descriptor."
o.prevErr = errors.New(errMsg)
Expand Down

0 comments on commit b65486d

Please sign in to comment.