Skip to content

Conversation

prestonvasquez
Copy link
Member

@prestonvasquez prestonvasquez commented Aug 30, 2024

GODRIVER-3322

Summary

bucket.UploadFromStream and bucket.UploadFromStreamWithID will pre-maturely cancel a context if a client-level timeout is set since the latter method creates the context and defers cancelation.

We should not cancel the client-scoped contexts after returning a download stream. Instead, keep the cancel() function on the stream objects and call it when Close() or Abort() are called. See GODRIVER-3325 for a more robust and long-term solution.

Background & Motivation

Discovered dogfooding evergreen.

@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the review-priority-low Low Priority PR for Review: within 3 business days label Aug 30, 2024
Copy link
Contributor

API Change Report

No changes found!

@prestonvasquez prestonvasquez added review-priority-urgent High Priority PR for Review: review immediately! and removed review-priority-low Low Priority PR for Review: within 3 business days labels Aug 30, 2024
@prestonvasquez prestonvasquez changed the title GODRIVER-3322 Apply client-level timeout to UploadFromStreamWithID GODRIVER-3323 Apply client-level timeout to UploadFromStreamWithID Aug 30, 2024
@prestonvasquez prestonvasquez changed the title GODRIVER-3323 Apply client-level timeout to UploadFromStreamWithID GODRIVER-3322 Apply client-level timeout to UploadFromStreamWithID Aug 30, 2024
})

// Create a new MongoClient with timeoutMS=10.
cliOptions := options.Client().SetTimeout(10).ApplyURI(mtest.ClusterURI())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean

.SetTimeout(10 * time.Millisecond)

?


// If the operation-level context is not respected, then the client-level
// timeout will exceed deadline.
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use:

.SetTimeout(10 * time.Millisecond)

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this test is to ensure that an operation-level context is actually used. Otherwise, this test would fail.

},
})

// Create a new MongoClient with timeoutMS=10.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be better to update the comment to describe the code more accurately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@qingyang-hu qingyang-hu Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, it looks good now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have missed something, but is the "timeoutMS=10" still accurate after bf50559? Where is the timeout set?

matthewdale
matthewdale previously approved these changes Sep 3, 2024
Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

qingyang-hu
qingyang-hu previously approved these changes Sep 3, 2024
matthewdale
matthewdale previously approved these changes Sep 5, 2024
Copy link
Collaborator

@qingyang-hu qingyang-hu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall with a question about the comment.

},
})

// Create a new MongoClient with timeoutMS=10.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have missed something, but is the "timeoutMS=10" still accurate after bf50559? Where is the timeout set?

Copy link
Collaborator

@qingyang-hu qingyang-hu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@prestonvasquez prestonvasquez merged commit cb89b1d into mongodb:master Sep 6, 2024
29 of 32 checks passed
@prestonvasquez prestonvasquez deleted the GODRIVER-3322 branch September 6, 2024 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-priority-urgent High Priority PR for Review: review immediately!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants