Skip to content

Commit 564e213

Browse files
authored
fix: canceled context should not start list before do listObjects (#2122)
1 parent 99a107f commit 564e213

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

api-list.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -759,13 +759,9 @@ func (c *Client) ListObjects(ctx context.Context, bucketName string, opts ListOb
759759
objectStatCh := make(chan ObjectInfo, 1)
760760
go func() {
761761
defer close(objectStatCh)
762-
send := func(obj ObjectInfo) bool {
763-
select {
764-
case <-ctx.Done():
765-
return false
766-
case objectStatCh <- obj:
767-
return true
768-
}
762+
if contextCanceled(ctx) {
763+
objectStatCh <- ObjectInfo{Err: ctx.Err()}
764+
return
769765
}
770766

771767
var objIter iter.Seq[ObjectInfo]
@@ -783,8 +779,11 @@ func (c *Client) ListObjects(ctx context.Context, bucketName string, opts ListOb
783779
}
784780
}
785781
for obj := range objIter {
786-
if !send(obj) {
782+
select {
783+
case <-ctx.Done():
784+
objectStatCh <- ObjectInfo{Err: ctx.Err()}
787785
return
786+
case objectStatCh <- obj:
788787
}
789788
}
790789
}()

0 commit comments

Comments
 (0)