Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internal/gensupport): check ctx in chunk retry #1364

Merged
merged 2 commits into from Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/gensupport/resumable.go
Expand Up @@ -177,6 +177,22 @@ func (rx *ResumableUpload) Upload(ctx context.Context) (resp *http.Response, err
return prepareReturn(resp, err)
}

// Check for context cancellation or timeout once more. If more than one
// case in the select statement above was satisfied at the same time, Go
// will choose one arbitrarily.
// That can cause an operation to go through even if the context was
// canceled before or the timeout was reached.
select {
case <-ctx.Done():
if err == nil {
err = ctx.Err()
}
return prepareReturn(resp, err)
case <-quitAfter:
return prepareReturn(resp, err)
tritone marked this conversation as resolved.
Show resolved Hide resolved
default:
}

resp, err = rx.transferChunk(ctx)

var status int
Expand Down
3 changes: 0 additions & 3 deletions internal/gensupport/resumable_test.go
Expand Up @@ -213,9 +213,6 @@ func TestCancelUploadFast(t *testing.T) {

tr := &interruptibleTransport{
buf: make([]byte, 0, mediaSize),
// Shouldn't really need an event, but sometimes the test loses the
// race. So, this is just a filler event.
events: []event{{"bytes 0-9/*", http.StatusServiceUnavailable}},
}

pr := progressRecorder{}
Expand Down